H,W = map(int,input().split()) G = [input() for _ in range(H)] ans = [[G[i][j] for j in range(W)] for i in range(H)] l = [(0,1),(0,-1),(1,0),(-1,0)] for i in range(H): for j in range(W): if ans[i][j] != ".": s = set() stack = [(i,j)] s.add((i,j)) a = ans[i][j] while stack: x,y = stack.pop() for xx,yy in l: if 0 <= x + xx < H and 0 <= y + yy < W: if (x + xx,y + yy) not in s and ans[x + xx][y + yy] == a: s.add((x + xx,y + yy)) stack.append((x + xx,y + yy)) if len(s) > 3: for x,y in s: ans[x][y] = "." for l in ans: print("".join(l))