import java.util.Scanner; public class Main { static int w; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); w = sc.nextInt(); char[][] g = new char[h][w]; for (int i = 0; i < h; i++) { g[i] = sc.next().toCharArray(); } sc.close(); int hw = h * w; UnionFind uf = new UnionFind(hw); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (i > 0) { if (g[i - 1][j] == g[i][j]) { uf.union(toInt(i - 1, j), toInt(i, j)); } } if (j > 0) { if (g[i][j - 1] == g[i][j]) { uf.union(toInt(i, j - 1), toInt(i, j)); } } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (uf.size(toInt(i, j)) >= 4) { g[i][j] = '.'; } } System.out.println(g[i]); } } static int toInt(int x, int y) { return x * w + y; } static class UnionFind { int[] parent, size; int num = 0; // 連結成分の数 UnionFind(int n) { parent = new int[n]; size = new int[n]; num = n; for (int i = 0; i < n; i++) { parent[i] = i; size[i] = 1; } } void union(int x, int y) { int px = find(x); int py = find(y); if (px != py) { parent[px] = py; size[py] += size[px]; num--; } } int find(int x) { if (parent[x] == x) { return x; } parent[x] = find(parent[x]); return parent[x]; } /** * xとyが同一連結成分か */ boolean same(int x, int y) { return find(x) == find(y); } /** * xを含む連結成分のサイズ */ int size(int x) { return size[find(x)]; } } }