from collections import deque from copy import deepcopy H,W=map(int,input().split()) G=[list(input()) for _ in range(H)] ans=deepcopy(G) dij=[(1,0),(-1,0),(0,1),(0,-1)] vis=[[False for _ in range(W)] for _ in range(H)] for i in range(H): for j in range(W): if vis[i][j]: continue if G[i][j]==".": continue vis[i][j]=True Q=deque() Q.append((i,j)) cands=[(i,j)] while len(Q): pi,pj=Q.popleft() for di,dj in dij: ni=pi+di nj=pj+dj if ni<0 or H<=ni: continue if nj<0 or W<=nj: continue if vis[ni][nj]: continue if G[ni][nj]==".": continue if G[pi][pj]==G[ni][nj]: vis[ni][nj]=True Q.append((ni,nj)) cands.append((ni,nj)) if len(cands)>=4: for ni,nj in cands: ans[ni][nj]="." for row in ans: for x in row: print(x,end="") print()