#include<iostream>
using namespace std;
int dp[20][20][2];
int x[20][20];
int H, W;
void A(int a, int b, int c, int d) {
	if (x[a][b] == 2) {
		if (d != 0) { return; }
		if (c == 1) { return; }
		if (c == 0) {
			if (x[a + 2][b] == 1) { return; }
			dp[a + 2][b][0] += dp[a][b][c];
			return;
		}
	}
	if (x[a + 1][b + d] == 1) { return; }
	if (x[a + 1][b + d] == 2 && d != 0) { return; }
	if (x[a][b] == 0) {
		if (d == 0) {
			dp[a + 1][b + d][0] += dp[a][b][c];
		}
		else {
			dp[a + 1][b + d][1] += dp[a][b][c];
		}
	}
}
int main() {
	while (true) {
		cin >> W >> H;
		if (H == 0 && W == 0) { break; }
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				cin >> x[i][j];
			}
		}
		for (int i = 0; i < 20; i++) {
			for (int j = 0; j < 20; j++) {
				dp[i][j][0] = 0;
				dp[i][j][1] = 0;
			}
		}
		for (int i = 1; i <= W; i++) {
			if (x[1][i] == 0) {
				dp[1][i][0] = 1;
			}
		}
		for (int i = 1; i <= H - 1; i++) {
			for (int j = 1; j <= W; j++) {
				A(i, j, 0, -1);
				A(i, j, 0, 0);
				A(i, j, 0, 1);
				A(i, j, 1, -1);
				A(i, j, 1, 0);
				A(i, j, 1, 1);
			}
		}
		int sum = 0;
		for (int j = H; j < 20; j++) {
			for (int i = 1; i <= W; i++) {
				sum += dp[j][i][0] + dp[j][i][1];
			}
		}
		cout << sum << endl;
	}
	return 0;
}