#include <bits/stdc++.h>
using namespace std;
struct node
{
int x,y,px,py;
};
node troll(int x, int y, int px, int py)
{
node t;
t.x=x;
t.y=y;
t.px=px;
t.py=py;
return t;
}
int main()
{
//freopen("input.txt","r",stdin);
ios_base::sync_with_stdio(false);
int m,n;
cin>>m>>n;
char a[m][n];
int temp,temp2;
queue<node> q;
for(temp=0;temp<m;temp++)
{
for(temp2=0;temp2<n;temp2++)
{
cin>>a[temp][temp2];
if(a[temp][temp2]=='#')
{
if(q.empty())
{
q.push(troll(temp,temp2,-1,-1));
}
}
}
}
bool visited[m][n];
int movex[]={1,-1,0,0},movey[]={0,0,1,-1};
memset(visited,0,sizeof(visited));
for(int tmp=0;tmp<2;tmp++)
{
pair<int,int> parent[m][n];
//printf("size of queue = %d\n",q.size());
while(!q.empty())
{
node t=q.front();
q.pop();
int x=t.x,y=t.y,px=t.px,py=t.py;
//printf("bfs(%d %d)\n",x,y);
if((x<0)||(x>=m)||(y<0)||(y>=n)) continue;
if(visited[x][y]) continue;
visited[x][y]=true;
parent[x][y]=make_pair(px,py);
//printf("parent (%d,%d) = (%d,%d)\n",x,y,px,py);
for(int temp=0;temp<4;temp++)
{
int nx=x+movex[temp],ny=y+movey[temp];
q.push(troll(nx,ny,x,y));
}
}
bool paint[m][n];
memset(paint,false,sizeof(paint));
memset(visited,false,sizeof(visited));
for(temp=0;temp<m;temp++)
{
for(temp2=0;temp2<n;temp2++)
{
if(a[temp][temp2]=='#')
{
int tm=temp,tn=temp2;
//printf("start = (%d,%d)\n",tm,tn);
while((tm!=-1)&&(tn!=-1))
{
if(visited[tm][tn]) break;
//printf("goto (%d,%d)\n",tm,tn);
paint[tm][tn]=true;
visited[tm][tn]=true;
int ttm=parent[tm][tn].first;
int ttn=parent[tm][tn].second;
tm=ttm;
tn=ttn;
}
}
}
}
for(temp=0;temp<m;temp++)
{
for(temp2=0;temp2<n;temp2++)
{
if(paint[temp][temp2])
{
cout<<'#';
}
else
{
cout<<'.';
}
if(a[temp][temp2]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