#include <iostream>
#include <vector>

using namespace std;

int main() {
	int x, y;
	while(cin >> x >> y) {
		if (x == 0 && y == 0) {
			break;
		}
	vector< vector<int> > data(y+1, vector<int>(x, 0));
	vector< vector<long long int> > cc(y+1, vector<long long int>(x, 0));
	for (int i = 0; i < y; i++) {
		for (int j = 0; j < x; j++) {
			cin >> data[i][j];
			if (i == 0 && data[i][j] != 1) {
				cc[i][j] = 1;
			}
		}
	}
	long long int ccc = 0;
	for (int i = 0; i < y-1; i++) {
		for (int j = 0; j < x; j++) {
			if (data[i][j] == 0) {
				if (i+1 < y+1) {
					if (j-1 >= 0) {
						if (data[i+1][j-1] == 0) {
							cc[i+1][j-1] += cc[i][j];
						}
					} 
					if (j+1 < x) {
						if (data[i+1][j+1] == 0) {
							cc[i+1][j+1] += cc[i][j];
						}
					}
					if (data[i+1][j] != 1) {
						cc[i+1][j] += cc[i][j];
					}
				}
			} else if (data[i][j] == 2) {
				if (i+2 < y+1) {
					if (data[i+2][j] != 1) {
						cc[i+2][j] += cc[i][j];
					}
				}
			}
			//cout << i << ' ' << j << endl;
		}
	}
	//cout << 'a' << endl;
	/*
	cout << endl;
	for (int i = 0; i < y+2; i++) {
		for (int j = 0; j < x; j++) {
			cout << cc[i][j] << ' ';
		}
		cout << endl;
	}*/
	for (int i = 0; i < x; i++) {
		ccc += cc[y][i]+cc[y-1][i];
	}
	cout << ccc << endl;
	}
	return 0;
}