#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	int map[100][100];
	int dp[100][100];
	
	int X, Y;
	while (scanf("%d %d", &X, &Y), X + Y){
		for (int i = 0; i < 100; i++){
			dp[0][i] = 1;
			for (int j = 1; j < 100; j++){
				dp[j][i] = 0;
			}
		}
		memset(map, 0, sizeof(map));
		
		for (int i = 0; i < Y; i++){
			for (int j = 0; j < X; j++){
				scanf("%d", &map[i][j]);
			}
		}
		
		for (int i = 0; i < Y; i++){
			for (int j = 0; j < X; j++){
				if (map[i][j] == 0){
					for (int k = -1; k <= 1; k++){
						if (j + k >= 0 && j + k < X && (map[i + 1][j + k] == 0 || (k == 0 && map[i + 1][j + k] == 2)) && (i < Y - 1 || k == 0)){
							dp[i + 1][j + k] += dp[i][j];
						}
					}
				}
				else if (map[i][j] == 2){
					dp[i + 2][j] += dp[i][j];
				}
			}
		}
		
		int sum = 0;
		for (int i = 0; i < X; i++){
//			printf("%d ", dp[Y][i]);
			sum += dp[Y][i];
			sum += dp[Y + 1][i];
		}
		
		printf("%d\n", sum);
	}
	
	return 0;
}