#include <iostream>
using namespace std;

int field[19][17];
int DP[19][17];
int main()
{
	int w,h;
	while(cin >> w >> h){
		if(!w && !h)
			break;
		for(int i=0;i<19;i++){
			for(int j=0;j<17;j++){
				field[i][j] = 0;
				DP[i][j] = 0;
			}
		}
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin >> field[i][j];
			}
		}
		for(int j=1;j<=w;j++){
			if(field[1][j] == 1)
				DP[1][j] = 0;
			else if(field[1][j] == 0)
				DP[1][j] = 1;
		}
		
		for(int i=2;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(field[i][j] == 1)
					DP[i][j] = 0;
				else if(field[i][j] == 0)
					DP[i][j] += DP[i-1][j-1] + DP[i-1][j] + DP[i-1][j+1];
				else if(field[i][j] == 2){
					DP[i][j] = 0;
					int dy = 0;
					while(field[i+dy][j] == 2){
						DP[i+dy][j] = 0;
						dy+=2;
					}
					DP[i+dy][j] += DP[i-1][j];
				}
			}
		}
		
		int sum = 0;
		for(int i=h;i<=h+2;i++){
			for(int j=1;j<=w;j++){
				sum += DP[i][j];
			}
		}
		cout << sum << endl;		
		/*
		for(int i=0;i<18;i++){
			for(int j=0;j<17;j++){
				cout << DP[i][j];
			}
			cout << endl;
		}*/
	}
	return 0;
}