#include
using namespace std;
bool ratMaze(char a[10][10], int sol[][10], int i, int j, int m, int n)
{
if (i == m && j == n)
{
sol[i][j] = 1;
for (int i = 0; i <= m; i++)
{
for (int j = 0; j <= n; j++)
{
cout << sol[i][j] << " ";
}
cout << endl;
}
return true;
}
if (i > m || j > n || i < 0 || j < 0)
{
return false;
}
if (a[i][j] == 'X')
{
return false;
}
sol[i][j] = 1;
bool down = ratMaze(a, sol, i + 1, j, m, n);
if (down)
return true;
bool left = ratMaze(a, sol, i, j + 1, m, n);
if (left)
return true;
bool right = ratMaze(a, sol, i, j - 1, m, n);
if (right)
return true;
bool up = ratMaze(a, sol, i - 1, j, m, n);
if (up)
return true;
sol[i][j] = 0;
return false;
}
int main()
{
int m, n;
cin >> m >> n;
char a[10][10];
int sol[10][10] = {0};
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cin >> a[i][j];
}
}
int i = 0, j = 0;
bool ans = ratMaze(a, sol, i, j, m - 1, n - 1);
if (ans == false)
{
cout << -1;
}
return 0;
}