#include <iostream>
using namespace std;

int main() {
	int X, Y;
	const int M = 2;
	while(cin >> X >> Y, X || Y) {
		long long table[128][128];
		int m[128][128];
		for(int i = 0; i < 128; i++) {
			for(int j = 0; j < 128; j++) {
				table[i][j] = 0;
				m[i][j] = 1;
			}
		}
		for(int i = M; i < Y + M; i++) {
			for(int j = M; j < X + M; j++) {
				int tmp;
				cin >> tmp;
				m[i][j] = tmp;
			}
		}

		for(int i = M; i < X + M; i++) {
			m[M-1][i] = 0;
			m[M+Y][i] = 0;
			m[M+Y+1][i] = 0;
			if(m[M][i] != 1)
				table[M][i] = 1;
		}

		for(int i = M; i < Y + M; i++) {
			for(int j = M; j < X + M; j++) {
				int dx[] = {-1, 0, 1};
				for(int k = 0; k < 3; k++) {
					if(m[i][j] == 2 && dx[k] == 0) {
						if((m[i + 2][j] == 2) || (m[i + 2][j] == 0))
							table[i + 2][j] += table[i][j];
					}
					else if(m[i][j] == 0) {
						if(((m[i + 1][j + dx[k]] == 2 && dx[k] == 0) || (m[i + 1][j + dx[k]] == 0)) && (i != Y + M - 1 || dx[k] == 0))
							table[i + 1][j + dx[k]] += table[i][j];
					}
				}
			}
		}

		/*
		for(int i = 0; i < Y + 2*M + 2; i++) {
			for(int j = 0; j < X + M*2; j++) {
				cout << table[i][j] << " ";
			}
			cout << endl;
		}
		*/

		long long ans = 0;
		for(int i = M; i < X + M; i++) {
			ans += table[Y+M][i];
			ans += table[Y+M+1][i];
		}
		cout << ans << endl;
	}
}