import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int h = sc.nextInt(); int w = sc.nextInt(); char[][] field = new char[h][]; UnionFindTree uft = new UnionFindTree(h * w); for (int i = 0; i < h; i++) { field[i] = sc.next().toCharArray(); for (int j = 0; j < w; j++) { if (i > 0) { if (field[i - 1][j] == field[i][j]) { uft.unite((i - 1) * w + j, i * w + j); } } if (j > 0) { if (field[i][j - 1] == field[i][j]) { uft.unite(i * w + j - 1, i * w + j); } } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (uft.getCount(i * w + j) >= 4) { field[i][j] = '.'; } } sb.append(new String(field[i])).append("\n"); } System.out.print(sb); } static class UnionFindTree { int[] parents; int[] counts; public UnionFindTree(int size) { parents = IntStream.range(0, size).toArray(); counts = new int[size]; Arrays.fill(counts, 1); } public int find(int x) { return x == parents[x] ? x : (parents[x] = find(parents[x])); } public boolean same(int x, int y) { return find(x) == find(y); } public void unite(int x, int y) { int xx = find(x); int yy = find(y); if (xx != yy) { parents[xx] = yy; counts[yy] += counts[xx]; } } public int getCount(int x) { return counts[find(x)]; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }