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

#define MAX_XY 16

int X, Y;
int field[MAX_XY][MAX_XY];
int way[MAX_XY][MAX_XY];

int main() {
	while (cin >> X >> Y, X || Y) {
		memset(field, 0, sizeof(field));
		memset(way, 0, sizeof(way));
		for (int i = 0; i < X; i++) {
			cin >> field[0][i];
			if (field[0][i] == 1) {
				way[0][i] = 0;
			} else {
				way[0][i] = 1;
			}
		}

		for (int i = 1; i < Y; i++) {
			for (int j = 0; j < X; j++) {
				cin >> field[i][j];
			}
		}

		for (int i = 0; i < Y-1; i++) {
			for (int j = 0; j < X; j++) {
				if (field[i][j] == 2 && field[i+2][j] != 1) {
					way[i+2][j] += way[i][j];
				} else {
					if (1 <= j && field[i+1][j-1] == 0) {
						way[i+1][j-1] += way[i][j];
					}
					if (j < X-1 && field[i+1][j+1] == 0) {
						way[i+1][j+1] += way[i][j];
					}
					if (field[i+1][j] != 1) {
						way[i+1][j] += way[i][j];
					}
				}
			}
		}

//		for (int i = 0; i < Y; i++) {
//			for (int j = 0; j < X; j++) {
//				cout << way[i][j] << ' ';
//			}
//			cout << endl;
//		}

		int cnt = 0;
		for (int i = 0; i < X; i++) {
			cnt += way[Y-1][i];
		}
		for (int i = 0; i < X; i++) {
			if (field[Y-2][i] == 2) cnt += way[Y-2][i];
		}

		cout << cnt << endl;

	}
	return 0;
}