#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int field[16][16];
// y,xÌ}X©çènßÄÅ«é·×èûÌ
int dp[16][16];

const int dy[]={1,1,1};
const int dx[]={-1,0,1};
int w,h;

int search(int sx,int sy){
	if(field[sy][sx]==2){
		if(sy>=h-2){
			return 1;
		}
		else if(field[sy+2][sx]==1)
			return 0;
		else{
			return search(sx,sy+2);
		}
	}
	if(dp[sy][sx]!=-1){
		return dp[sy][sx];
	}
	int cnt=0;
	for(int i = 0; i < 3; i++){
		int nx=sx+dx[i];
		int ny=sy+dy[i];
		if(nx>=0&&nx<w&&field[ny][nx]!=1){
			if(ny>h-1){
				cnt++;
			}
			else if(ny==h-1&&field[ny][nx]==0){
				cnt++;
			}
			else if(field[ny][nx]==2&&dx[i]==0){
				cnt+=search(nx,ny);
			}
			else if(field[ny][nx]==0){
				cnt+=search(nx,ny);
			}
		}
	}

	dp[sy][sx]=cnt;
	return dp[sy][sx];
}


int main(){

	while(cin>>w>>h&&!(w==0&&h==0)){
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
				dp[i][j]=-1;
			}
		}
		int sum=0;
		for(int i = 0; i < w; i++){
			if(field[0][i]==0)
				sum+=search(i,0);
		}
		cout<<sum<<endl;
	}

	return 0;
}