#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int x,y;
	while(1){
		cin>>x>>y;
		if(!(x||y))break;
		int status[y][x],dp[y][x];
		rep(i,y){
			rep(j,x){
				cin>>status[i][j];
			}
		}
		int sum=0;
		rep(i,y){
			rep(j,x){
				if(i==0 && status[i][j]!=1)dp[i][j]=1;
				else dp[i][j]=0;
			}
		}
		rep(i,y){
			rep(j,x){
				if(status[i][j]==1)continue;
				if(status[i][j]==2){
					if(i>=y-2)sum+=dp[i][j];
					else dp[i+2][j]+=dp[i][j];
					continue;
				}
				if(i==y-1)sum+=dp[i][j];
				else{
					if(j==0){
						if(status[i+1][j]!=1)dp[i+1][j]+=dp[i][j];
						if(status[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
					}else if(j==x-1){
						if(status[i+1][j]!=1)dp[i+1][j]+=dp[i][j];
						if(status[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
					}else{
						if(status[i+1][j]!=1)dp[i+1][j]+=dp[i][j];
						if(status[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
						if(status[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
					}
				}
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}