import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) #input = sys.stdin.readline #alist = list(map(int,input().split())) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = collections.defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return ''.join(f'{r}: {m}' for r, m in self.all_group_members().items()) #alist = [] #s = input() h,w = map(int,input().split()) #for i in range(n): # alist.append(list(map(int,input().split()))) grid = [list(input().rstrip()) for i in range(h)] uf = UnionFind(h*w) for i in range(h): for j in range(w): if i != h-1 and grid[i][j] == grid[i+1][j]: uf.union(i*w+j,(i+1)*w+j) if j != w-1 and grid[i][j] == grid[i][j+1]: uf.union(i*w+j,i*w+j+1) for i in range(h): for j in range(w): print(grid[i][j] if uf.size(i*w+j) < 4 else '.',end='') print()