class UnionFind(): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] H, W = map(int, input().split()) N = H * W U = UnionFind(N) S = [] for i in range(H): S.append(list(input())) def f(x, y): return x * W + y for i in range(H): for j in range(W - 1): if S[i][j] == S[i][j + 1]: U.union(f(i,j), f(i,j+1)) for i in range(H - 1): for j in range(W): if S[i][j] == S[i + 1][j]: U.union(f(i,j), f(i+1,j)) ans = [] for i in range(H): temp = [] for j in range(W): if U.get_size(f(i,j)) >= 4: temp.append(".") else: temp.append(S[i][j]) print(*temp, sep="")