#include
using namespace std;
bool ratInMaze(char grid[1001][1001],int sol[1001][1001] ,int i,int j,int m,int n){
if(i==m && j==n){
sol[m][n]=1;
for(int i=0;i<=m;i++){
for(int j=0;j<=n;j++){
cout<<sol[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
return true;
}
if(i>m || j>n ){
return false ;
}
if( grid[i][j]=='X'){
return false;
}
sol[i][j]=1;
bool rigth_dir=ratInMaze(grid,sol,i,j+1,m,n);
bool down_dir=ratInMaze(grid,sol,i+1,j,m,n);
sol[i][j]==0;
if(rigth_dir || down_dir){
return true;
}
return false ;
}
int main() {
int n,m;
cin>>m>>n;
char grid[1001][1001];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>grid[i][j];
}
}
int sol [1001][1001]={0};
int ans=ratInMaze(grid,sol,0,0,m-1,n-1);
if(ans==false){
cout<<-1<<endl;
}
return 0;
}