#include <bits/stdc++.h>  

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int X, Y;
int field[20][20];
int dp[20][20];

int main() {
	while(scanf("%d %d", &X, &Y), X || Y) {
		rep(i, Y) rep(j, X) field[i][j] = 1;
		rep(i, Y) rep(j, X) scanf("%d", &field[i][j]);
		memset(dp, 0, sizeof(dp));
		rep(j, X) dp[0][j] = (field[0][j] == 0);
		rep(i, Y - 1) rep(j, X) {
			if(field[i][j] == 0) {
				if(field[i + 1][j] != 1) dp[i + 1][j] += dp[i][j];
				if(j - 1 >= 0 && field[i + 1][j - 1] == 0) dp[i + 1][j - 1] += dp[i][j];
				if(j + 1 < X && field[i + 1][j + 1] == 0) dp[i + 1][j + 1] += dp[i][j];
			}
			else if(field[i][j] == 2) {
				dp[i + 2][j] += dp[i][j];
			}
		}
		/*rep(i, Y) {
			rep(j, X) printf("%2d", dp[i][j]);
			puts("");
		}
		rep(i, X) printf("%2d", dp[Y][i]);
		*/
		int res = 0;
		rep(i, X) if(field[Y - 1][i] != 1) res += dp[Y - 1][i];
		rep(i, X) res += dp[Y][i];
		printf("%d\n", res);
	}
	return 0;
}