from collections import deque H,W=map(int,input().split()) G=[list(input()) for _ in range(H)] ans=[["" for _ in range(W)] for _ in range(H)] for i in range(H): for j in range(W): if ans[i][j]==".":continue now=G[i][j] vis=[[0 for _ in range(W)] for _ in range(H)] Q=deque([(i,j)]) while Q: ci,cj=Q.popleft() vis[ci][cj]=1 for di,dj in [(-1,0),(1,0),(0,-1),(0,1)]: if 0<=ci+di=4: for ii in range(H): for jj in range(W): if vis[ii][jj]==1:ans[ii][jj]="." else: ans[i][j]=G[i][j] for i in range(H): print("".join(ans[i]))