#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
using namespace std;

int cost[501][501],xx,yy,n,m;
char mat[501][501];
bool visit[501][501],first = true;

int a[] = {-1,0,0,1}, b[] = {0,-1,1,0};

void check(int x,int y,int level) {
  visit[x][y] = true;
  cost[x][y] = level;
  for(int i = 0; i < 4; ++i) {
    xx = x + a[i];
    yy = y + b[i];
    if(0 <= xx and xx < n and 0 <= yy and yy < m and mat[xx][yy] == '.') {
      if(level + 1 < cost[xx][yy] or !visit[xx][yy]) check(xx,yy,level + 1);
    }
  }
}

int max() {
  int r = -1;
  for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) if(mat[i][j] == '.') r = max(r,cost[i][j]);
  return r;
}

void show() {
  if(!first) puts("---");
  int r = max();
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < m; ++j) {
      if(cost[i][j] == r) printf("X");
      else printf("%c",mat[i][j]);
    }
    puts("");
  }
}

int main() {
  while(scanf("%d %d",&n,&m) == 2) {
    queue<pair<int,int> > cola;
    for(int i = 0; i < n; ++i) {
      scanf("\n");
      for(int j = 0; j < m; ++j) {
        scanf("%c",&mat[i][j]);
        if(mat[i][j] == 'V') cola.push(make_pair(i,j));
      }
    }
    memset(cost,-1,sizeof cost);
    memset(visit,0,sizeof visit);
    while(!cola.empty()) {
      pair<int,int> aux = cola.front();
      check(aux.first, aux.second,0);
      cola.pop();
    }
    show();
    first = false;
  }
  return 0;
}
