from collections import defaultdict,deque H,W=list(map(int,input().split())) MAP=[] for i in range(H): s=input() MAP.append(s) ANS=[] for i in range(H): ANS.append(["."]*W) for i in range(H): for j in range(W): ANS[i][j]=MAP[i][j] check=set() for i in range(H): for j in range(W): if (i,j) in check: continue Q=deque() c=set() Q.append((i,j)) c.add((i,j)) while len(Q)>0: x,y=Q.popleft() if x>0: if (x-1,y) not in check and MAP[x-1][y]==MAP[x][y]: c.add((x-1,y)) Q.append((x-1,y)) if x0: if (x,y-1) not in check and MAP[x][y-1]==MAP[x][y]: c.add((x,y-1)) Q.append((x,y-1)) if y=4: for x,y in c: ANS[x][y]="." for k in c: check.add(k) for i in range(H): print("".join(ANS[i]))