#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

bool is_inside(int x, int y, int X, int Y){
	if(x < 0 || y < 0 || x >= X || y >= Y){
		return false;
	}
	return true;
}

int main(){
	
	int X, Y;
	
	int course[20][20];
	long long int sum[20][20];
	
	while(true){
		cin >> X >> Y;
		
		if(X == 0 && Y == 0){
			break;
		}
		
		for(int i = 0; i < Y; i++){
			for(int j = 0; j < X; j++){
				cin >> course[j][i];
				sum[j][i] = 0;
			}
		}
		
		for(int i = 0; i < X; i++){
			sum[i][0] = 1;
		}
		
		for(int y = 0; y < Y; y++){
			for(int x = 0; x < X; x++){
				if(course[x][y] == 0){
					for(int dx = -1; dx <= 1; dx++){
						if(is_inside(x + dx, y + 1, X, Y)){
							if(course[x + dx][y + 1] != 2 || dx == 0){
								sum[x + dx][y + 1] += sum[x][y];
							}
						}
					}
				}else if(course[x][y] == 2){
					if(is_inside(x, y + 2, X, Y)){
						sum[x][y + 2] += sum[x][y];
					}
				}else{
					sum[x][y] = 0;
				}
			}
		}
		
		long long int ans = 0;
		
		for(int i = 0; i < X; i++){
			if(course[i][Y - 1] == 0){
				ans += sum[i][Y - 1];
			}
			if(Y >= 2 && course[i][Y - 2] == 2){
				ans += sum[i][Y - 2];
			}
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}