H,W=map(int, input().split()) #A=list(map(int, input().split())) A=[] for i in range(H): s=list(input()) A.append(s) N=H*W par=[i for i in range(N)] rank=[0]*(N) friend=[0]*N block=[0]*N size=[1]*N def find(x): if par[x]==x: return x else: par[x]=find(par[x]) return par[x] #同じ集合か判定 def same(x,y): return find(x)==find(y) def union(x,y): x=find(x) y=find(y) if x==y: return if rank[x]>rank[y]: par[y]=x size[x]+=size[y] else: par[x]=y size[y]+=size[x] if rank[x]==rank[y]: rank[y]+=1 for h in range(H): for w in range(W): if h!=0: if A[h][w]==A[h-1][w]: p=h*W+w;q=(h-1)*W+w union(p,q) if w!=0: if A[h][w]==A[h][w-1]: p=h*W+w;q=h*W+w-1 union(p,q) ans=[] for h in range(H): for w in range(W): p=h*W+w s=size[find(p)] if s>=4: A[h][w]='.' for a in A: print(''.join(a))