#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int H, W;
int maps[15][15];
ll dp[15][15];

int dx[3] = {1,0,-1}, dy[3] = {1,1,1};

int main() {
	while (cin >> W >> H, H || W) {
		REP(i, H) REP(j, W) scanf("%d", &maps[i][j]);
		
		memset(dp, 0, sizeof(dp));
		REP(j, W) dp[0][j] = maps[0][j] != 1;
		
		REP(i, H) REP(j, W) if (dp[i][j]) {
			
			if (maps[i][j] == 2) { // jump
				if (i + 2 < H && maps[i + 2][j] == 1) continue;
				dp[min(i + 2, H - 1)][j] += dp[i][j];
			}
			else { // normal
				REP(k, 3) {
					int yy = i + dy[k], xx = j + dx[k];
					if (!(yy >= 0 && yy < H && xx >= 0 && xx < W)) continue;
					if (maps[yy][xx] == 1 || (k != 1 && maps[yy][xx] == 2)) continue;
					dp[yy][xx] += dp[i][j];
				}
			}
		}
		
		ll ans = 0;
		REP(j, W) ans += dp[H - 1][j];
		cout << ans << endl;
	}
	return 0;
}