#include <cstdio>
using namespace std;

int X, Y, c[15][15], dp[15][15];

int main(){
	while (scanf("%d%d", &X, &Y), X != 0) {
		for (int i = 0; i < Y; i++) {
			for (int j = 0; j < X; j++) {
				scanf("%d", &c[i][j]);
				dp[i][j] = 0;
			}
		}
		for (int i = 0; i < Y; i++) {
			for (int j = 0; j < X; j++) {
				if (i == 0 && c[i][j] != 1) {
					dp[i][j] = 1;
				}
				else {
					if (c[i][j] == 1) {
						if (i > 0 && c[i - 1][j] == 2) {
							dp[i][j] = dp[i - 1][j];
						}
						else {
							dp[i][j] = 0;
						}
					}
					else if (c[i][j] == 2) {
						dp[i][j] = dp[i - 1][j];
					}
					else {
						dp[i][j] = dp[i - 1][j];
						if (j > 0 && c[i-1][j-1] == 0) {
							dp[i][j] += dp[i - 1][j - 1];
						}
						if (j < X - 1 && c[i-1][j+1] == 0) {
							dp[i][j] += dp[i - 1][j + 1];
						}
					}
				}
			}
		}
		int sum = 0;
		for (int i = 0; i < X; i++) {
			sum += dp[Y - 1][i];
		}
		printf("%d\n", sum);
	}

	return 0;
}