import java.util.*;
public class Main {
static boolean ans = false;
static boolean p = false;
static Scanner sc = new Scanner(System.in);
public static char[][] insert(int n, int m) {
char[][] board = new char[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
board[i][j] = sc.next().charAt(0);
}
}
return board;
}
public static void display2(int[][] result) {
for (int i = 0; i < result.length; i++) {
for (int j = 0; j < result[i].length; j++) {
System.out.print(result[i][j]+" “);
}
System.out.println(” ");
}
}
public static void ratMaze(char[][] borad,int[][] result,int row, int col,int n,int m) {
if (row == n-1 && col == m-1) {
result[row][col] = 1;
if (!p) {
display2(result);
p = true;
ans = true;
}
}
if (row == 0 && col == m-1) {
}
if (row == n || row < 0 || col == m || col < 0 || borad[row][col] == 'X') {
return;
}
result[row][col] = 1;
ratMaze(borad, result, row, col+1, n, m);
ratMaze(borad, result, row+1, col, n, m);
result[row][col] = 0;
return ;
}
public static void main(String[] args) {
int N = sc.nextInt();
int M = sc.nextInt();
char[][] board = insert(N, M);
int[][] result = new int[N][M];
ratMaze(board, result, 0, 0, N, M);
if (!ans) {
System.out.println("-1");
}
}
}