#include<iostream>
#include<vector>
using namespace std;
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid);
int main()
{
int m=2,n=2;
cin>>m;
cin>>n;
vector<vector<int> > obstacleGrid;
int value;
vector<int> temp;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>value;
temp.push_back(value);
}
obstacleGrid.push_back(temp);
temp.clear();
}
cout<<uniquePathsWithObstacles(obstacleGrid)<<endl;
return 0;
}
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid)
{
int m = obstacleGrid.size();
int n = obstacleGrid[0].size();
long record[m][n];
if(obstacleGrid[0][0]==1)
{
record[0][0]=0;
}
else
{
record[0][0]=1;
}
for(int i=1;i<m;i++)
{
if(obstacleGrid[i][0]==1)
{
record[i][0]=0;
}
else
{
record[i][0]=record[i-1][0];
}
}
for(int i=1;i<n;i++)
{
if(obstacleGrid[0][i]==1)
{
record[0][i]=0;
}
else
{
record[0][i]=record[0][i-1];
}
}
for(int i=1;i<m;i++)
{
for(int j=1;j<n;j++)
{
if(obstacleGrid[i][j]==1)
{
record[i][j]=0;
}
else
{
record[i][j]=record[i-1][j]+record[i][j-1];
}
}
}
return record[m-1][n-1];
}