h,w=map(int,input().split()) g=[list(input()) for i in range(h)] v=[[0]*w for i in range(h)] for i in range(h): for j in range(w): if g[i][j]!="." and v[i][j]==0: c=g[i][j] u=[] q=[(i,j)] v[i][j]=1 for sx,sy in q: u+=[(sx,sy)] dx,dy=1,0 for _ in range(4): tx,ty=sx+dx,sy+dy dx,dy=-dy,dx if 0<=tx=4: for x,y in u: g[x][y]="." for i in range(h): print("".join(g[i]))