#include <bits/stdc++.h>
using namspace std;

int main(void)
{
  int H, W;
  cin >> H >> W;
  string S[50];
  
  for (int i=0;i<H;i++){
    cin >> S[i];
  }
  
  bool can = true;
  int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
  
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      if (S[i][j] != '#') continue;
      
      for (int k=0;k<8;k++){
        int ni = i + dy[k];
        int nj = j + dx[k];
        
        if (S[ni][nj] == '#') break;
      }
      if (k == 8){
        can = false;
      }
    }
    if (!can) break;
  }
  
  for (int i=0;i<H;i++){
    cout << S[i] << endl;
  }
  
  return 0;
}