#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
#include<map>
#include<string>
using namespace std;

int X, Y, Fld[17][15], memo[14][15];

int DFS(int y, int x){
	if(y >= Y-1) return 1;
	if(Fld[y][x] == 2) return DFS(y+2, x);
	if(memo[y][x] != -1) return memo[y][x];
	memo[y][x] = 0;

	for(int i = -1; i <= 1; i++){
		int ny = y+1, nx = x + i;
		if( nx < 0 || X <= nx || Fld[ny][nx] == 1 || (Fld[ny][nx] == 2 && i != 0) )
			continue;
		memo[y][x] += DFS(ny, nx);
	}

	return memo[y][x];
}

int main(){
	while(cin >> X >> Y, X || Y){
		fill_n( (int*)Fld, 17*15, 0 );
		for(int i = 0; i < Y; i++){
			for(int j = 0; j < X; j++){
				cin >> Fld[i][j];
			}
		}

		int ans = 0;
		fill_n( (int*)memo, 14*15, -1 );
		for(int i = 0; i < X; i++) if(Fld[0][i] == 0) ans += DFS(0, i);
		printf("%d\n", ans);
	}
	return 0;
}