#include <cstring>
#include <iostream>
using namespace std;
const int MAX_W = 15;
const int MAX_H = 15;

int w, h;
int field[MAX_H + 1][MAX_W + 2];
int dp[MAX_H + 1][MAX_W + 2];

void printfield() {
	for (int i = 0; i < h + 1; i++) {
		for (int j = 0; j <= w + 1; j++) {
			cout << '\t' << dp[i][j] << '(' << field[i][j] << ')';
		}
		cout << endl;
	}
}

int main () {
	while (cin >> w >> h, w || h) {
		memset(field, 0, sizeof(field));
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < h + 1; i++) {
			field[i][0] = 1;
			dp[i][0] = 0;
			field[i][w + 1] = 1;
			dp[i][w + 1] = 0;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 1; j <= w; j++) {
				cin >> field[i][j];
			}
		}
		for (int i = 1; i <= w; i++) {
			if (field[0][i] == 0) dp[0][i] = 1;
		}
		for (int i = 0; i < h - 1; i++) {
			for (int j = 1; j <= w; j++) {
				if (field[i][j] == 0) {
					dp[i + 1][j] += dp[i][j];
					if (field[i + 1][j + 1] != 2) dp[i + 1][j + 1] += dp[i][j];
					if (field[i + 1][j - 1] != 2) dp[i + 1][j - 1] += dp[i][j];
				}
				else if (field[i][j] == 2) {
					dp[i + 2][j] += dp[i][j];
				}
			}
		}
//		printfield();
		int sum = 0;
		for (int i = h - 1; i < h + 1; i++) {
			for (int j = 1; j <= w; j++) {
				if (field[i][j] != 1) {
					sum += dp[i][j];
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}