#include <cstdio>

int main(){
	while(true){
		int X, Y;
		scanf("%d%d", &X, &Y);
		if(X == 0 || Y == 0){ break; }
		int field[16][17] = { { 0 } };
		for(int y = 1; y <= Y; y++){
			for(int x = 1; x <= X; x++){
				scanf("%d", &(field[y][x]));
			}
		}
		int dp[16][17] = { { 0 } };
		for(int x = 1; x <= X; x++){
			if(field[1][x] != 1){ dp[1][x] = 1; }
		}
		for(int y = 2; y <= Y; y++){
			for(int x = 1; x <= X; x++){
				if(field[y][x] == 1){ continue; }
				int sum = 0;
				if(field[y][x] == 0){
					if(field[y - 1][x - 1] == 0){ sum += dp[y - 1][x - 1]; }
					if(field[y - 1][x + 1] == 0){ sum += dp[y - 1][x + 1]; }
				}
				if(field[y - 1][x] == 0){ sum += dp[y - 1][x]; }
				if(field[y - 2][x] == 2){ sum += dp[y - 2][x]; }
				dp[y][x] = sum;
			}
		}
		int answer = 0;
		for(int x = 1; x <= X; x++){
			if(field[Y - 1][x] == 2){ answer += dp[Y - 1][x]; }
			answer += dp[Y][x];
		}
		printf("%d\n", answer);
	}
	return 0;
}