#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

const int moveTo[][2] = {{-1,1},{0,1},{1,1}};

int stage[17][17];
int sum=0;

void dfs(int sx,int sy,int w,int h){
	//space:0 tree:1 jump:2

	int now = stage[sy][sx];
	if(now == 1) return;

	if(sy>=h-1){
		sum++;
		return;
	}

	if(now == -1) return;

	if(now == 2){
		int dx = sx;
		int dy = sy + 2;
		if(!(dx < 0 || dx >= w || dy < 0)){
			if(!(stage[dy][dx] == 1)){
				dfs(dx,dy,w,h);
			}
		}

	}

	else{
		for(int i=0;i<3;i++){
			int dx = sx + moveTo[i][0];
			int dy = sy + moveTo[i][1];
			if(dx < 0 || dx >= w || dy < 0) continue;
			if(stage[dy][dx] == 2 && dx != sx) continue;
			if(stage[dy][dx] == 1) continue;

			dfs(dx,dy,w,h);
		}
	}
}

int main(){
	int w,h;
	while(~scanf("%d %d",&w,&h)){
		if(w==h && h==0) break;
		memset(stage,-1,sizeof(stage));
		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				scanf("%d",&stage[y][x]);
			}
		}

		int res = 0;
		for(int sx=0;sx<w;sx++){
			dfs(sx,0,w,h);
		}

		printf("%d\n",sum);
		sum = 0;
	}
}