#include
using namespace std;
bool RatinMaze(char **maze,int **soln,int i,int j,int n,int m)
{
if(i==n && j==m)
{
soln[n][m]=1;
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
cout<<soln[i][j]<<" ";
cout<<endl;
}
cout<<endl;
return true;
}
if(i>n || j>m)
return false;
if(maze[i][j]=='X')
return false;
soln[i][j]=1;
bool rightsuccess=RatinMaze(maze,soln,i,j+1,m,n);
bool downsuccess=RatinMaze(maze,soln,i+1,j,m,n);
soln[i][j]=0;
if(rightsuccess||downsuccess)
return true;
return false;
}
int main()
{
int n,m;
cin>>n>>m;
char **maze=new char*[n];
for(int i=0;i<n;i++)
maze[i]=new char[m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cin>>maze[i][j];
}
int **soln=new int*[n];
for(int i=0;i<n;i++)
soln[i]=new int[m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
soln[i][j]=0;
}
bool ans=RatinMaze(maze,soln,0,0,n-1,m-1);
if(ans==false)
cout<<"-1";
}