#include <iostream>
using namespace std;

int w, h, c[15][15];
int res;

void dfs(int x, int y) {
	if (y <= h-1 && c[y][x] == 1) return;
	if (y >= h-1) {
		++res;
		return;
	}
	if (c[y][x] == 0) {
		for (int i = 0; i < 3; ++i) {
			int nx = x + i - 1, ny = y + 1;
			if (0 <= nx && nx < w && ((x == nx && c[ny][nx] == 2) || c[ny][nx] == 0)) dfs(nx, ny);
		}
	}
	if (c[y][x] == 2) dfs(x, y+2);
	return;
}

int main(void) {
	while (cin >> w >> h, w && h) {
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) cin >> c[i][j];
		}
		res = 0;
		for (int i = 0; i < w; ++i) {
			if (c[0][i] == 0) dfs(i, 0);
		}
		cout << res << endl;
	}
	return 0;
}