#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
using namespace std;

#define NONE 0
#define TREE 1
#define JUMP 2

int dp[17][17];
int area_state[17][17];
int h,w;

int solve(int y, int x){

	if (dp[y][x] != -1)
		return dp[y][x];
	if (x == 0 || x == w+1){
		dp[y][x] = 0;
		return 0;
	}	
	if (y == h || y == h+1){
		dp[y][x] = 1;
		return 1;
	}

	if (area_state[y][x] == TREE){
		return 0;

	}else if (area_state[y][x] == JUMP){
		dp[y][x] = (solve(y+2, x));
		return dp[y][x];

	}else if (area_state[y][x] == NONE){
		if(y == h-1){
			dp[y][x] = 1;
			return 1;
		}
		int left = 0;
		int right = 0;

		if(area_state[y+1][x-1] != JUMP){
			left = solve(y+1,x-1);
		}
		if(area_state[y+1][x+1] != JUMP){
			right =  solve(y+1,x+1);
		}
		dp[y][x] =  left + solve(y+1,x) + right;
		return dp[y][x];
	}
}


int main() {
	while (cin >> w >> h && w&&h ){ 
		fill( dp[0], dp[17], -1);
		fill( area_state[0], area_state[17], 0);

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				int zone;
				cin >> zone;
				area_state[i][j+1] = zone;
			}
		}

		int ans = 0;
		for(int i = 1; i < w+1; i++){
			ans += solve(0,i);
		}

		// cout << endl;

		// for(int i = 0; i < h+2; i++){
		// 	for(int j = 0; j < w+2; j++){
		// 		printf("%4d",area_state[i][j]);
		// 	}
		// 	cout << endl;
		// }
		// cout << endl;

		// for(int i = 0; i < h+2; i++){
		// 	for(int j = 0; j < w+2; j++){
		// 		printf("%4d",dp[i][j]);
		// 	}
		// 	cout << endl;
		// }
		
		cout << ans << endl;
	}
	return 0;
}