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 G[i][j]==".":ans[i][j]=".";continue if ans[i][j]!="":continue now=G[i][j] vis=set() Q=deque([(i,j)]) while Q: ci,cj=Q.popleft() vis.add((ci,cj)) for di,dj in [(-1,0),(1,0),(0,-1),(0,1)]: if 0<=ci+di=4: for ii,jj in vis: ans[ii][jj]="." else: for ii,jj in vis: ans[ii][jj]=G[ii][jj] for i in range(H): print("".join(ans[i]))