from collections import deque def bfs(si, sj, moji):#sensorsからパクった que = deque() que.append((si, sj)) positions = [] while que: oi, oj = que.popleft() positions.append((oi, oj)) for ni, nj in neighbor8(oi, oj): if not seen[ni][nj] and S[ni][nj] == moji: seen[ni][nj] = True que.append((ni, nj)) return positions def neighbor8(i, j):#sensorsからパクった2 lst = [] for di in [-1, 0, 1]: for dj in [-1, 0, 1]: if di == dj == 0: continue if 0 <= i + di < H and 0 <= j + dj < W: lst.append((i + di, j + dj)) return lst H, W = map(int, input().split()) S = [list(input()) for _ in range(H)] seen = [[False] * W for _ in range(H)] for i in range(H): for j in range(W): if not seen[i][j]: positions = bfs(i, j, S[i][j]) if len(positions) > 4: for pi, pj in positions: S[pi][pj] = '.' for row in S: print(''.join(row))