#include <iostream>

using namespace std;

int X, Y;
int field[17][17];
int dp[18][17];

void solve() {
	fill(dp[0], dp[17], 0);
	for (int x = 1; x <= X; x++)
		if (field[1][x] == 0) dp[1][x] = 1;
	for(int y = 1; y < Y; y++)
		for (int x = 1; x <= X; x++) {
			switch (field[y][x]) {
			case 0:
				if(field[y+1][x-1] == 0) dp[y + 1][x - 1] += dp[y][x];
				dp[y + 1][x] += dp[y][x];
				if(field[y+1][x+1] == 0) dp[y + 1][x + 1] += dp[y][x];
				break;
			case 2:
				dp[y + 2][x] += dp[y][x];
			default:
				break;
			}
		}
	int sum = 0;
	for(int y = Y; y <= Y+1; y++)
		for (int x = 1; x <= X; x++) 
			if (field[y][x] != 1) sum += dp[y][x];
	cout << sum << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> X >> Y, X, Y) {
		fill(field[0], field[17], 0);
		for (int y = 1; y <= Y; y++)
			for (int x = 1; x <= X; x++)
				cin >> field[y][x];
		solve();
	}
}