#include<iostream>

using namespace std;

int main() {
	int x, y;
	while (cin >> x >> y, x * y) {//
		int skimap[15][15] = {};//x = j y = i
		int dp[15][15] = {};//x = j y = i
		int flyover = 0;
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				cin >> skimap[i][j];
			}
		}
		for(int i = 0; i < x;i++){
			if (skimap[0][i] == 0)dp[0][i] = 1;
		}
		for (int i = 0; i < y - 1; i++) {
			for (int j = 0; j < x; j++) {
				if (skimap[i][j] == 0) {
					if (j - 1 >= 0) {
						if (skimap[i + 1][j - 1] == 0) {
							dp[i + 1][j - 1] += dp[i][j];
						}
					}
					if (skimap[i + 1][j] != 1)dp[i + 1][j] += dp[i][j];
					if (j + 1 < x) {
						if (skimap[i + 1][j + 1] == 0) {
							dp[i + 1][j + 1] += dp[i][j];
						}
					}
				}
				else if (skimap[i][j] == 1) {
					continue;
				}else {
					if (i + 2 < y) {
						dp[i + 2][j] = dp[i][j];
					}else {
						flyover += dp[i][j];
					}
				}
			}
		}
		int sum = flyover;
		for (int i = 0; i < x; i++) {
			sum += dp[y - 1][i];
		}
		cout << sum << endl;
	}
	return 0;
}