#include<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)

int main(){
	while(1){
		int w,h;
		cin>>w>>h;
		if(w==0)break;
		
		int dp[22][22]={0};
		int masu[22][22]={0};
		
		reps(i,h){
			reps(j,w){
				cin>>masu[i][j];
			}
		}
		
		reps(j,w){
			dp[1][j]=1;
		}
		
		reps(i,h-1){
			reps(j,w){
				if(masu[i][j]==0){
					if(masu[i+1][j]!=1) dp[i+1][j]+=dp[i][j];
					if(masu[i+1][j-1]==0) dp[i+1][j-1]+=dp[i][j];
					if(masu[i+1][j+1]==0) dp[i+1][j+1]+=dp[i][j];
				}
				if(masu[i][j]==1){
					
				}
				if(masu[i][j]==2){
					if(masu[i+2][j]!=1)dp[i+2][j]+=dp[i][j];
				}
			}
		}
		int ans=0;
		rep(i,2){
			reps(j,w){
				ans += dp[h+i][j];
			}
		}
		printf("%d\n",ans);
	}
}