#int-input def II(): return int(input()) def MI() -> int : return map(int, input().split()) class fenwick_tree(): n=1 data=[0 for i in range(n)] def __init__(self,N): self.n=N self.data=[0 for i in range(N)] def add(self,p,x): assert 0<=p0): s+=self.data[r-1] r-=r&-r return s class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a0: result2.append(result[i]) return result2 h,w = MI() g = [input() for i in range(h)] ans = [[""]*w for i in range(h)] uf = dsu(h*w) for i in range(h): for j in range(w): if i != h-1 and g[i][j] == g[i+1][j]: uf.merge(i*w+j,(i+1)*w+j) if j != w-1 and g[i][j] == g[i][j+1]: uf.merge(i*w+j,i*w+j+1) for i in range(h): for j in range(w): if uf.size(i*w+j) >= 4: ans[i][j] = "." else: ans[i][j] = g[i][j] for i in ans: print("".join(i))