#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		vector<vector<int>>masu(b + 1, vector<int>(a));
		vector<vector<int>>suberikata(b + 1, vector<int>(a));
		for (int c = 0; c < b; c++) {
			for (int d = 0; d < a; d++) {
				cin >> masu[c][d];
			}
		}
		for (int e = 0; e < b; e++) {
			if (masu[0][e] ==0)suberikata[0][e]++;
		}
		for (int f = 0; f < b-1; f++) {
			for (int g = 0; g < a; g++) {
				switch (masu[f][g]) {
				case 0:
					suberikata[f + 1][g] += suberikata[f][g];
					if (g > 0&&masu[f+1][g-1]!=2)suberikata[f + 1][g - 1] += suberikata[f][g];
					if (g < a - 1 && masu[f + 1][g + 1] != 2)suberikata[f + 1][g + 1] += suberikata[f][g];
					break;     
				case 1:break;
				case 2:suberikata[f + 2][g] += suberikata[f][g]; break;
				}
			}
		}
		int s = 0;
		for (int j : suberikata[suberikata.size() - 2]) {
			s += j;
		}
		cout << s << endl;
	}
}