#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt"

int main() {
	while (1) {
		int H, W; cin >> W >> H;
		if (!H)break;
		vector<vector<int>>field(H + 3, vector<int>(W + 2,1));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cin >> field[i][j+1];
			}
		}
		for (int i = H; i < H + 3; ++i) {
			for (int j = 1; j <= W; ++j) {
				field[i][j] = 0;
			}
		}
		vector<vector<long long int>>nums(H + 3, vector<long long int>(W + 2, 0));
		for (int j = 0; j < W + 2; ++j) {
			if (!field[0][j])nums[0][j] = 1;
		}
		long long int ans = 0;
		for (int i = 0; i < H-1; ++i) {
			for (int j = 1; j < W + 1; ++j) {
				for (int dx = -1; dx <= 1;++dx) {
					const int nextx = j + dx;
					int nexty = i + 1;
					
					if (field[nexty][nextx] == 1) {

					}
					else if (field[nexty][nextx] == 2) {
						if (!dx) {
							while (1) {
								nexty += 2;
								if (nexty >= H - 1 && field[nexty][nextx] != 1) {
									ans += nums[i][j];
									break;
								}
								else {
									if (field[nexty][nextx] == 1) {
										break;
									}
									else if (field[nexty][nextx] == 0) {

										nums[nexty][nextx] += nums[i][j];
										break;
									}
								}
							}
							
						}
					}
					else {
						if (nexty >= H - 1)ans += nums[i][j];
						else {
							nums[nexty][nextx] += nums[i][j];
						}
					}
				}
				
			}
		}
		cout << ans << endl;
	}
	return 0;
}