#include <iostream>
using namespace std;

int main()
{
  int N, M, i, j;
	cin >> N >> M;
	char matrica[N][M];
	for (i=0; i < N; i++) {
	  for (j=0; j < M; j++) {
	  cin >> matrica[i][j];
	}
	}
	for (i=0; i < N; i++) {
	  for (j=0; j < M; j++) {
	    if (matrica[i][j] == 'X') {
	      matrica[i-1][j] = 'X';
	      matrica[i+1][j] = 'X';
	      matrica[i][j+1] = 'X';
	      matrica[i][j-1] = 'X';
	    }
	    if (matrica[i][j] = 'S') {
	      if (matrica[i+1][j] = '.') {
	        matrica[i+1][j] = 'S';
	      }
	       if (matrica[i-1][j] = '.') {
	        matrica[i-1][j] = 'S';
	      }
	       if (matrica[i][j+1] = '.') {
	        matrica[i][j+1] = 'S';
	      }
	       if (matrica[i][j-1] = '.') {
	        matrica[i][j-1] = 'S';
	      }
	    }
	  }
	}
	for (i=0; i < N; i++) {
	  for (j=0; j < M; j++) {
	cout << matrica[i][j];
	  }
	  cout << endl;
	}
}