#include<stdio.h>

int main(void){
	int X,Y;
	
	while(scanf("%d%d", &X, &Y) && X && Y){
		int masu[32][32]={0};
		int co[32][32]={0};
		int ans = 0;
		for(int i = 0; i < Y; i++){
			for(int j = 0; j < X; j++){
				scanf("%d", &masu[i][j]);
			}
		}
		
		for(int i = 0; i < X; i++){
			co[0][i] = 1;
		}
		
		for(int i = 0; i < Y-1; i++){
			for(int j = 0; j < X; j++){
				if(masu[i][j] == 0){
					if(masu[i+1][j] != 1)co[i+1][j] += co[i][j];
					if(masu[i+1][j+1] == 0)co[i+1][j+1] += co[i][j];
					if(masu[i+1][j-1] == 0 && j-1 > -1)co[i+1][j-1] += co[i][j];
				}else if(masu[i][j] == 2){
					co[i+2][j] += co[i][j];
				}
			}
		}
		for(int i = 0; i < X; i++){
			co[Y][i] += co[Y-1][i];
		}
		
		
		for(int i = 0; i < X; i++){
			ans += co[Y][i];
		}
		printf("%d\n",ans);
	}
	return 0;
}