#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int a[20][20],dp[20][20];
int main(){
	int h,w;
	while(cin>>w>>h&&h+w){
		lol(i,h)lol(j,w)cin>>a[i][j];
		lol(i,h)lol(j,w){
			dp[i][j]=0;
			if(a[i][j]==1)continue;
			if(i){
				if(a[i-1][j]==0)dp[i][j]=dp[i-1][j];
				if(i>1)if(a[i-2][j]==2)dp[i][j]+=dp[i-2][j];
				if(a[i][j]==0){
					if(j>0)if(a[i-1][j-1]==0)dp[i][j]+=dp[i-1][j-1];
					if(j<w-1)if(a[i-1][j+1]==0)dp[i][j]+=dp[i-1][j+1];
				}
			}
			else dp[i][j]=1;
		}
		int ans=0;
		lol(j,w){
			ans+=dp[h-1][j];
			if(h>=2)if(a[h-2][j]==2)ans+=dp[h-2][j];
		}
		cout<<ans<<endl;
	}
	return 0;
}