#include<iostream>
using namespace std;

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

int main(){
	while(1){
		cin >> X >> Y;
		if(X == 0 && Y == 0) break;
		for(int i=0;i<20;i++){
			for(int j=0;j<20;j++){
				memo[20][20] = -1;
			}
		}
		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){
	if(memo[y][x] == -1) return memo[y][x];
	if(mas[y][x] == 1) return 0;
	if(y>=Y-1) return 1;
	if(mas[y][x] == 2) return (memo[y][x] = dfs(x,y+2));
	else{
		int cou = 0;
		for(int i=-1;i<2;i++){
			int nx = x + i;
			int ny = y + 1;
			if(nx >= 0 && nx < X && ((i == 0 && mas[ny][nx] == 2) || (mas[ny][nx] == 0))){
				cou += dfs(nx,ny);
			}
		}
		return (memo[y][x] = cou);
	}
}