#include<iostream>
using namespace std;

int dfs(int x,int y);
int mas[20][20];
int X,Y;

int main(){
	while(1){
		cin >> X >> Y;
		if(X == 0 && Y == 0) break;
		for(int i=0;i<Y;i++){
			for(int j=0;j<X;j++){
				cin >> mas[i][j];
			}
		}
		int ans = 0;
		for(int i=0;i<X;i++){
			if(mas[0][i] == 0){
				ans += dfs(i,0);
			}
		}
		cout << ans << endl;
	}
}

int dfs(int x,int y){
	int cou = 0;
	if(y>=Y-1) return 1;
	for(int i=-1;i<2;i++){
		int nx = x + i;
		int ny = y + 1;
		if(nx >= 0 && nx < X){
			if(i == 0 && mas[ny][nx] == 2){
				while(mas[ny][nx] == 2){
					ny += 2;
				}
				cou += dfs(nx,ny);
			}
			else if(mas[ny][nx] == 0){
				cou += dfs(nx,ny);
			}
		}
	}
	return cou;
}