import numpy as np ways = [ [1 + 0j, 2 + 0j, 3 + 0j], [1 + 0j, 2 + 0j, 2 + 1j], [1 + 0j, 1 + 1j, 2 + 1j], [1 + 0j, 1 + 1j, 1 + 2j], [1 + 0j, 1 + 1j, 0 + 1j], ] def main(): H, W = [int(a) for a in input().split(" ")] grid = dict() # grid = [["." for j in range(W + 6)] for i in range(H + 6)] for a in range(H - 1, -1, -1): k = list(input()) for b in range(len(k)): grid[complex(b, a)] = k[b] # print(grid) erasable = dict() for a in range(H - 1, -1, -1): for b in range(W): x = grid[complex(b, a)] for way in ways: w = way for _ in range(4): four = True for step in w: if grid.get(complex(b, a) + step) != x: four = False if four: erasable[complex(b, a)] = True # print(complex(b, a)) for step in w: erasable[complex(b, a) + step] = True # print(complex(b, a) + step) # print() w = [step * (0 + 1j) for step in w] for a in range(H - 1, -1, -1): for b in range(W): if erasable.get(complex(b, a)): print(".", end="") else: print(grid[complex(b, a)], end="") print() main()