#include<iostream>
using namespace std;

int DP[17][17];
int field[17][17];
int x,y;

int main(){
	while(true){
		cin >> x >> y;
		if(!x && !y)
			return 0;
		
		for(int i=1; i<=y; i++)
			for(int k=1; k<=x; k++)
				cin >> field[i][k];
		for(int i=1; i<=x; i++)
			field[y+1][i] = 0;
		
		for(int i=1; i<=y+1; i++)
			for(int k=0; k<=x+1; k++){
				DP[i][k]=0;
				if(i==1 && k>0 && k<=x){
					if(field[i][k] == 0)
						DP[i][k] = 1;
					else if(field[i][k] == 2){
						DP[i][k] = 0;
						int n = i+2;
						while(true){
							if(field[n][k] == 0){
								DP[n][k] = 1;
								break;
							}else if(field[n][k] == 1)
								break;
							else
								n+=2;
						}
					}
				}
			}
		
		for(int i=2; i<=y; i++){
			for(int k=1; k<=x; k++){
				if(field[i][k] == 0)
					DP[i][k] += DP[i-1][k-1] + DP[i-1][k] + DP[i-1][k+1];
				else if(field[i][k] == 1)
					DP[i][k] = 0;
				else{
					DP[i][k] = 0;
					int n = i+2;
					while(true){
						if(field[n][k] == 0){
							DP[n][k] += DP[i-1][k];
							break;
						}else if(field[n][k] == 1)
							break;
						else
							n+=2;
					}
				}
			}
		}
		
		int ans=0;
		for(int i=y; i<=y+1; i++)
			for(int k=1; k<=x; k++)
				ans += DP[i][k];
		cout << ans << endl;
	}
}