from collections import deque h,w=map(int,input().split()) S=[list(input()) for _ in range(h)] V=[[1]*w for _ in range(h)] for i in range(h): for j in range(w): if V[i][j]: V[i][j]=0 d=deque([(i,j)]) A=[(i,j)] while d: p,q=d.popleft() if p and V[p-1][q] and S[p-1][q]==S[p][q]: d.append((p-1,q)) V[p-1][q]=0 A.append((p-1,q)) if q and V[p][q-1] and S[p][q-1]==S[p][q]: d.append((p,q-1)) V[p][q-1]=0 A.append((p,q-1)) if p=4: for x,y in A: S[x][y]='.' for x in S: print(''.join(x))