#include <iostream>
using namespace std;

int mx,my;
int count;
int field[17][17];//field[y][x];

void init()
{
	for(int i=0;i<17;i++){
		for(int j=0;j<17;j++){
			field[i][j] = 0;
		}
	}
}

void DFS(int x,int y)
{
	if(y >= my-1){
		count++;
		return;
	}
	int dx,dy;
	dx = x-1;dy = y+1;
	if(0<=dx && dx < mx && field[dy][dx] == 0)
		DFS(dx,dy);
	dx = x;dy = y+1;
	if(0<=dx && dx < mx && field[dy][dx] != 1){
		if(field[dy][dx]==2){
			while(field[dy][dx]==2){
				dy+=2;
			}
		}
		DFS(dx,dy);
	}
	dx = x+1;dy = y+1;
	if(0<=dx && dx < mx && field[dy][dx] == 0)
		DFS(dx,dy);
	return;
}

int main()
{
	while(cin >> mx >> my){
		if(mx == 0 && my == 0)
			break;
		for(int i=0;i<my;i++){
			for(int j=0;j<mx;j++){
				cin >> field[i][j];
			}
		}
		count = 0;
		for(int i=0;i<mx;i++){
			if(field[0][i] == 0){
				DFS(i,0);
			}
		}
		cout << count << endl;
	}
	return 0;
}