// Arup Guha
// 2/22/2025
// Solution to Kattis Problem: Fountain
// https://open.kattis.com/problems/fontan

import java.util.*;

public class fontan {

	public static int r;
	public static int c;
	public static char[][] grid;
	
	public static void main(String[] args) {
	
		// Get size of grid.
		Scanner stdin = new Scanner(System.in);
		r = stdin.nextInt();
		c = stdin.nextInt();
		
		// Read grid. I am adding an air row below.
		grid = new char[r+1][c];
		for (int i=0; i<r; i++)
			grid[i] = stdin.next().toCharArray();
		Arrays.fill(grid[r], '.');
		r++;
		
		// Go backwards so I don't have to do as many redundant calculations.
		for (int i=r-1; i>=0; i--) {
			for (int j=0; j<c; j++) {
			
				// Either we've marked it or it's not a loop.
				if (grid[i][j] != 'V') continue;
				
				// Add to tally and recursively mark loop.
				fill(i, j);
			}
		}
		
		// Ta da! (We go <r-1 since I don't want to print my last row.)
		for (int i=0; i<r-1; i++)
			System.out.println(new String(grid[i]));
	}
	
	// Recursively "rains" at spot x,y
	public static void fill(int x, int y) {
		
		// Just in case.
		if (!inbounds(x,y)) return;
		
		// Mark it.
		grid[x][y] = 'V';
		
		// Go down.
		if (inbounds(x+1,y) && grid[x+1][y] == '.')
			fill(x+1, y);
		
		// Go across.
		else if (inbounds(x+1,y) && grid[x+1][y] == '#') {
			if (y-1>=0 && grid[x][y-1] == '.') fill(x, y-1);
			if (y+1<c && grid[x][y+1] == '.') fill(x, y+1);
		}
	}
	
	// Returns inf x, y is in bounds on my adjusted grid (the way I call it).
	public static boolean inbounds(int x, int y) {
		return x>=0 && x<r && y>=0 && y<c;
	}
}