#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second

int dat[30][30];
int dp[30][30];
int main(void){
	int x,y;
	for(;;){
		scanf("%d%d",&x,&y);
		if(x==0)break;
		rep(j,y)rep(i,x){
			scanf("%d",&dat[i][j]);
		}
		memset(dp,0,sizeof(dp));
		rep(i,x)if(dat[i][0]==0)dp[i][0]=1;
		rep(j,y)rep(i,x){
			if(dat[i][j]==1)continue;
			if(dat[i][j]==2){
				if(dat[i][j+2]!=1)dp[i][j+2]+=dp[i][j];
				continue;
			}
			if(j!=y-1){
				if(i>0 && dat[i-1][j+1]==0){
					dp[i-1][j+1]+=dp[i][j];
				}
				if(i<x-1 && dat[i+1][j+1]==0){
					dp[i+1][j+1]+=dp[i][j];
				}
			}
			if(dat[i][j+1]!=1)dp[i][j+1]+=dp[i][j];
		}
		lli ans=0;
		/*
		printf("\n");
		rep(j,y){
			rep(i,x){
				//printf("(%2d %2d)",dat[i][j],dp[i][j]);
				printf("%2d",dp[i][j]);
			}
			printf("\n");
		}*/
		reg(j,y,y+1){
			//printf("\n");
			rep(i,x){
				//printf("%2d ",dp[i][j]);
				ans+=dp[i][j];
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}