#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;


signed main() {
	int y, x;
	while (1) {
		cin >> y >> x;
		if (y + x == 0) break;
		int d[20][20] = { -1 };
		rep(i, 0, y) {
			rep(j, 0, x) {
				cin >> d[i][j];
			}
		}
		int dp[20][20] = { 0 };
		rep(i, 0, x) {
			if (d[0][i] == 0) dp[0][i] = 1;
		}
		rep(i, 0, y) {
			rep(j, 0, x) {
				if (d[i][j] == 1) continue;
				if (d[i][j] == 2) {
					dp[i + 2][j] += dp[i][j];
					continue;
				}
				rep(k, -1, 2) {
					if (j + k < 0 || j + k >= x || d[i + 1][j + k] != 0) continue;
					dp[i + 1][j + k] += dp[i][j];
				}
				if (d[i + 1][j] == 2) {
					dp[i + 1][j] += dp[i][j];
				}
			}
		}
		/*cout << endl;
		rep(i, 0, y + 2) {
			rep(j, 0, x) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}*/
		int ans = 0;
		rep(i, 0, x) {
			ans += dp[y - 1][i];
			if (d[y - 2][i] == 2) {
				ans += dp[y - 2][i];
			}
		}
		cout << ans << endl;
	}
}