// AOJ 0203
#include <iostream>

using namespace std;

int main(void)
{
	int x, y;
	while (cin >> x >> y, x || y){
		int field[32][32];
		for (int i = 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				cin >> field[i][j];
			}
		}
		int dp[32][32];
		for (int i = 0; i < 32; i++) {
			for (int j = 0; j < 32; j++){
				dp[i][j] = 0;
			}
		}

		for (int j = 1; j <= x; j++){
			if (field[1][j] == 0){
				dp[1][j] = 1;
			}
		}
		for (int i = 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				if (field[i][j] == 1){
					continue;
				}
				if (field[i][j] == 2){
					dp[i + 2][j] += dp[i][j];
					continue;
				}
				if (field[i + 1][j - 1] == 0){
					dp[i + 1][j - 1] += dp[i][j];
				}
				if (field[i + 1][j] != 1){
					dp[i + 1][j] += dp[i][j];
				}
				if (field[i + 1][j + 1] == 0){
					dp[i + 1][j + 1] += dp[i][j];
				}
			}
		}

		// for (int i = 1; i <= y; i++){
		// 	for (int j = 1; j <= x; j++){
		// 		cout << dp[i][j] << " ";
		// 	}
		// 	puts("");
		// }

		int ret = 0;
		for (int i = y - 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				if (i == y - 1){
					if (field[i][j] == 2) ret += dp[i][j];
					continue;
				}
				else {
					ret += dp[i][j];
					// cout << i << " " << j << endl;
					// cout << ret << endl;
				}
			}
		}
		cout << ret << endl;
	}

	return 0;
}