from itertools import product DIJ = ((0, 1), (0, -1), (1, 0), (-1, 0)) def main(): H, W = map(int, input().split()) board = [list(input()) for _ in range(H)] def is_valid_pos(h: int, w: int) -> bool: return 0 <= h < H and 0 <= w < W visited = set() for h, w in product(range(H), range(W)): if (h, w) in visited: continue current_con = set() q = [(h, w)] while q: cur = q.pop() if cur in current_con: continue current_con.add(cur) visited.add(cur) for dij in DIJ: next_ = (cur[0]+dij[0], cur[1]+dij[1]) if next_ in visited: continue if not is_valid_pos(*next_): continue if board[cur[0]][cur[1]] != board[next_[0]][next_[1]]: continue q.append(next_) if len(current_con) < 4: continue for mass in current_con: board[mass[0]][mass[1]] = "." for row in board: print("".join(row)) if __name__ == "__main__": main()