#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class point {
public:
	long long num;
	int block;
	point() :num(0), block(1) {}
};
int main() {
	int X, Y;
	while (cin >> X >> Y&&X != 0) {
		vector<vector<point> > map(X + 2, vector<point>(Y + 2));
		for (int y = 1; y <= Y; ++y) {
			for (int x = 1; x <= X; ++x) {
				cin >> map[x][y].block;
			}
		}
		for (int i = 1; i <= X; ++i) {
			map[i][1].num = 1;
		}
		for (int y = 1; y < Y; ++y) {
			for (int x = 1; x <= X; ++x) {
				if (map[x][y].block == 0) {
					for (int k = -1; k <= 1; ++k) {
						if (map[x + k][y + 1].block == 0 || (map[x + k][y + 1].block == 2 && k == 0) ) {
							map[x + k][y + 1].num += map[x][y].num;
						}
					}
				}
				else if (map[x][y].block == 2) {
					if (y + 2 > Y)map[x][Y].num += map[x][y].num;
					else if (map[x][y + 2].block != 1) {
						map[x][y + 2].num += map[x][y].num;
					}
				}
			}
		}
		long long ans = 0;
		for (int i = 1; i <= X; ++i) {
			ans += map[i][Y].num;
		}
		cout << ans << endl;
	}
	return 0;
}