#include <iostream>
#include <cstdio>

using namespace std;

int X, Y;
int field[15 + 2][15 + 2];
int dp[15 + 2][15 + 2];

void solve() {
	for (int i = 1; i <= X; i++) {
		if (field[0][i] == 0) {
			dp[0][i] = 1;
		}
	}
	for (int y = 0; y < Y; y++) {
		for (int x = 1; x <= X; x++) {
			if (field[y][x] == 2) {
				if (field[y + 2][x] != 1) {
					dp[y + 2][x] += dp[y][x];
				}
			} else if (field[y][x] == 0) {
				if (field[y + 1][x - 1] == 0) {
					dp[y + 1][x - 1] += dp[y][x];
				}
				if (field[y + 1][x] != 1) {
					dp[y + 1][x] += dp[y][x];
				}
				if (field[y + 1][x + 1] == 0) {
					dp[y + 1][x + 1] += dp[y][x];
				}
			}
		}
	}
	int sum = 0;
	for (int y = Y; y <= Y + 1; y++) {
		for (int x = 1; x <= X; x++) {
			sum += dp[y][x];
		}
	}
	printf("%d\n", sum);
}

int main() {
	while (scanf("%d %d ", &X, &Y) == 2) {
		if (X == 0 && Y == 0) {return 0;}

		fill(dp[0], &dp[15 + 2 - 1][15 + 2], 0);
		fill(field[0], &field[15 + 2 - 1][15 + 2], 1);
		for (int y = Y; y <= Y + 1; y++) {
			for (int x = 1; x <= X; x++) {
				field[y][x] = 2;
			}
		}
		for (int i = 0; i < Y; i++) {
			for (int j = 1; j <= X; j++) {
				scanf("%d ", &field[i][j]);
			}
		}
		/*
		for (int i = 0; i < Y + 2; i++) {
			for (int j = 0; j < X + 2; j++) {
				printf("%d ", field[i][j]);
			}
			printf("\n");
		}
		*/
		solve();
		/*
		for (int i = 0; i < Y + 2; i++) {
			for (int j = 0; j < X + 2; j++) {
				printf("%2d ", dp[i][j]);
			}
			printf("\n");
		}
		*/
	}
}