#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){
    int in[15][15]={0};
    int out[15][15]={0};
    rep(i,m){
      cin>>in[0][i];
      if(in[0][i]==0)out[0][i]=1;
    }
    loop(i,1,n){
      rep(j,m){
	cin>>in[i][j];
	if(in[i][j]==0){
	  if(j-1>=0&&in[i-1][j-1]!=2)out[i][j]+=out[i-1][j-1];
	  if(in[i-1][j]!=2)out[i][j]+=out[i-1][j];
	  if(j+1<m&&in[i-1][j+1]!=2)out[i][j]+=out[i-1][j+1];
	  if(i-2>=0&&in[i-2][j]==2)out[i][j]+=out[i-2][j];
	}else if(in[i][j]==2){
	  out[i][j]+=out[i-1][j];
	  if(i-2>=0&&in[i-2][j]==2)out[i][j]+=out[i-2][j];
	}
      }
    }
    int ans=0;
    rep(i,m){
      ans+=out[n-1][i];
      if(in[n-2][i]==2)ans+=out[n-2][i];
    }
    cout<<ans<<endl;
    //cout<<endl;
    //rep(i,n){rep(j,m)cout<<" "<<out[i][j];cout<<endl;}
    //cout<<endl;
  }
}