#include <iostream>
#include <cstring>
using namespace std;

int main() {
	int map[15][15];
	int dp[16][15];
	int X, Y;
	int dx[] = { -1, 0, 1 };

	while (cin >> X >> Y, X||Y) {
		memset(dp, 0, sizeof(dp));

		for (int i=0; i<Y; i++)
		for (int j=0; j<X; j++)
			cin >> map[i][j];

		for (int i=0; i<X; i++) { 
			dp[0][i] = (map[0][i]==1) ? 0 : 1;
			dp[Y][i] = 0;
		}

		for (int y=0; y<Y-1; y++)
		for (int x=0; x<X; x++) {
			int p;
			switch (map[y][x]) {
				case 0:
					for (int i=0; i<3; i++) {
						p = x + dx[i];
						if (p<0 || p>=X) continue;
						if (map[y+1][p]==1 || (map[y+1][p]==2 && i!=1)) continue;
						dp[y+1][p] += dp[y][x];
					}
					break;
				case 1:
					break;
				case 2:
					if (map[y+2][x]!=1) dp[y+2][x] += dp[y][x];
					break;
			}
		}
		
		int ans = 0;
		for (int i=0; i<X; i++)
			ans += dp[Y-1][i] + dp[Y][i];

		cout << ans << endl;
	}
	return 0;
}