#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>m>>n,n||m){
    vector<vector<int> >in(n,vector<int>(m));
    vector<vector<int> >dp(n+1,vector<int>(m));
    rep(i,n)rep(j,m)cin>>in[i][j];
    rep(i,m)if(in[0][i]==0)dp[0][i]=1;
    loop(i,1,n+1){
      rep(j,m){
	if(i<n&&in[i][j]==1)continue;
	else if(i!=n){
	  if(j!=0&&in[i-1][j-1]==0&&in[i][j]!=2)dp[i][j]+=dp[i-1][j-1];
	  if(in[i-1][j]==0)dp[i][j]+=dp[i-1][j];
	  if(j!=m&&in[i-1][j+1]==0&&in[i][j]!=2)dp[i][j]+=dp[i-1][j+1];
	  if(i!=1&&in[i-2][j]==2)dp[i][j]+=dp[i-2][j];
	}else if(i-2>=0&&in[i-2][j]==2)dp[i][j]+=dp[i-2][j];
      }      
    }
    int sum=0;
    //rep(i,n+1){rep(j,m)printf(" %2d",dp[i][j]);puts("");}
    loop(i,n-1,n+1)rep(j,m)sum+=dp[i][j];
    cout<<sum<<endl;
  }
}