#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 2002;
char a[N][N];
int n, m;
queue<pair<int, int> > q;
int dir[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1};
bool check(int x, int y) {
  if (a[x][y] == '.' || x < 1 || y < 1 || x > n || y > m) return 0;
  if (a[x][y - 1] == '.' && a[x - 1][y - 1] == '.' && a[x - 1][y] == '.')
    return 1;
  if (a[x][y + 1] == '.' && a[x - 1][y + 1] == '.' && a[x - 1][y] == '.')
    return 1;
  if (a[x][y - 1] == '.' && a[x + 1][y - 1] == '.' && a[x + 1][y] == '.')
    return 1;
  if (a[x][y + 1] == '.' && a[x + 1][y + 1] == '.' && a[x + 1][y] == '.')
    return 1;
  return 0;
}
int main() {
  while (~scanf("%d%i", &n, &m)) {
    while (!q.empty()) q.pop();
    for (int i = 1; i <= n; ++i) scanf("%s", a[i] + 1);
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        if (check(i, j)) q.push(make_pair(i, j));
      }
    }
    while (!q.empty()) {
      int x = q.front().first;
      int y = q.front().second;
      q.pop();
      if (!check(x, y)) continue;
      a[x][y] = '.';
      for (int i = 0; i < 8; ++i) {
        int xx = x + dir[i][0];
        int yy = y + dir[i][1];
        if (check(xx, yy)) q.push(make_pair(xx, yy));
      }
    }
    for (int i = 1; i <= n; ++i) puts(a[i] + 1);
  }
  return 0;
}
