#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;

int w, h;
vvi field;
vvi memo;

int solve(int y, int x)
{
	if(memo[y][x] != -1)
		return memo[y][x];
	
	memo[y][x] = 0;
	if(field[y][x] == 1)
		return 0;
	if(y == 0)
		return memo[y][x] = 1;
	
	const int dx[] = {-1, 0, 1};
	rep(i, 3){
		int px = x + dx[i];
		if(px<0 || w<=px || field[y-1][px]!=0 || (field[y][x]==2 && dx[i]!=0))
			continue;
		memo[y][x] += solve(y-1, px);
	}
	
	if(y>=2 && field[y-2][x] == 2)
		memo[y][x] += solve(y-2, x);
	return memo[y][x];
}

int main()
{
	while(scanf("%d%d", &w, &h), w){
		field.assign(h, vi(w));
		memo.assign(h, vi(w, -1));
		rep(i, h) rep(j, w)
			scanf("%d", &field[i][j]);

		int sum = 0;
		rep(i, w){
			sum += solve(h-1, i);
			if(h>=2 && field[h-2][i] == 2)
				sum += solve(h-2, i);
		}
		printf("%d\n", sum);
	}
	return 0;
}