class UF: def __init__(self,n): self.p = [-1]*n def f(self,x): if self.p[x]<0: return x else: self.p[x] = self.f(self.p[x]); return self.p[x] def u(self,x,y): x = self.f(x); y = self.f(y) if x==y: return if -self.p[x]<-self.p[y]: x,y = y,x self.p[x] += self.p[y]; self.p[y] = x def n(self,x): return -self.p[self.f(x)] h,w = map(int,input().split()) g = [list(input()) for _ in range(h)] uf = UF(h*w) for i in range(h): for j in range(w-1): if g[i][j]==g[i][j+1]: uf.u(i*w+j,i*w+(j+1)) for j in range(w): for i in range(h-1): if g[i][j]==g[i+1][j]: uf.u(i*w+j,(i+1)*w+j) for i in range(h): for j in range(w): if uf.n(i*w+j)>=4: g[i][j] = "." for a in g: print("".join(a))