#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int mp[16][16];
int dp[16][16];
int main() {
	int x, y;
	while (cin >> x >> y, x) {
		memset(dp, 0, sizeof(dp));
		rep(i, y)rep(j, x)cin >> mp[i][j];
		rep(i, x)if (!mp[0][i])dp[0][i] = 1;
		rep(i, y - 1)rep(j, x) {
			if (mp[i][j] == 0) {
				if (j > 0 && !mp[i + 1][j - 1])dp[i + 1][j - 1] += dp[i][j];
				if (mp[i + 1][j] != 1)dp[i + 1][j] += dp[i][j];
				if (j + 1 < x && !mp[i + 1][j + 1])dp[i + 1][j + 1] += dp[i][j];
			}
			if (mp[i][j] == 2 && i + 2 < y&&mp[i + 2][j] != 1)
				dp[i + 2][j] += dp[i][j];
		}
		int sum = 0;
		rep(i, x) {
			if (mp[y - 2][i] == 2)sum += dp[y - 2][i];
			sum += dp[y - 1][i];
		}
		cout << sum << endl;
	}
}