#include <iostream>

using namespace std;

int gole, X, Y;
int map[15][15];

bool check(int x, int y, int flag) { // flag: ツ陳シツ進ツつオツづつォツつスツつゥ
	if (x < 0 || x >= X) return false;
	if (y >= Y) { gole += flag; return false; }
	if (map[y][x] == 1) return false;
	if (!flag && map[y][x] == 2) return false;
	return true;
}

int main() {
	while (cin >> X >> Y, X || Y) {
		int pattern[15][15] = {0};
		gole = 0;
		for (int y = 0; y < Y; ++y)
			for (int x = 0; x < X; ++x)
				cin >> map[y][x];

		for (int x = 0; x < X; ++x)
			if (map[0][x] == 0)
				pattern[0][x] = 1;

		for (int y = 1; y < Y; ++y)
			for (int x = 0; x < X; ++x) {
				if (map[y-1][x] == 0) {
					if (check(x-1, y, false)) pattern[y][x-1] += pattern[y-1][x];
					if (check(x,   y, true))  pattern[y][x]   += pattern[y-1][x];
					if (check(x+1, y, false)) pattern[y][x+1] += pattern[y-1][x];
				}
				else if (map[y-1][x] == 1) continue;
				else if (check(x, y+1, pattern[y-1][x])) pattern[y+1][x] += pattern[y-1][x];
			};

		for (int x = 0; x < X; ++x) gole += pattern[Y-1][x];

		cout << gole << endl;
	}
	return 0;
}