h,w=map(int,input().split())

s=[list(input())for i in range(h)]

t=[[0]*w for i in range(h)]

for i in range(h):
	for j in range(w):
		if t[i][j]:continue
		Q=[(i,j)]
		Q2=[(i,j)]
		di=[1,0,-1,0]
		dj=[0,1,0,-1]

		t[i][j]=1

		while len(Q):
			pi,pj=Q.pop()
			for k in range(4):
				ni=pi+di[k]
				nj=pj+dj[k]
				if 0<=ni<h and 0<=nj<w and s[i][j]==s[ni][nj] and not t[ni][nj]:
					t[ni][nj]=1
					Q.append((ni,nj))
					Q2.append((ni,nj))
		if len(Q2)<4:continue
		for e in Q2:
			s[e[0]][e[1]]="."

for i in s:print("".join(i))