#include<iostream>

using namespace std;

int main()
{
	for(;;){
		int x, y;
		int map[100][100];
		int dp[100][100];
		
		cin >> x;
		cin >> y;
		if(x == 0 && y == 0){
			break;
		}
		
		for(int i = 0; i < y; i++){
			for(int j = 0; j < x; j++){
				cin >> map[i][j];
			}
		}
		
		//ツ鳴催渉可づ可暗ェツ氾板湘」ツづ個療アツづ個づつィツづィツ青板づーツ個按津ィ
		//0:ツ暗堋督ョツ嘉つ能
		//1:ツ湘。ツ害ツ閉ィ
		//2:ツジツδδδ督プツ妥、
		
		for(int i = 0; i < x; i++){
			dp[0][i] = map[0][i] == 0;
		}
		
		const int dx[] = {-1,0,1};
		
		for(int i = 1; i < y; i++){
			for(int j = 0; j < x; j++){
				if(map[i][j] == 0 || map[i][j] == 2){
					dp[i][j] = 0;
					for(int k = 0; k < 3; k++){
						int px = j+dx[k];
						if(px < 0 || x <= px || map[i-1][px] == 2 || (map[i][j] == 2 && dx[k] != 0)){
							continue;
						}
						dp[i][j] += dp[i-1][px];
					}
					if(i-2 >= 0 && map[i-2][j] == 2){
						dp[i][j] += dp[i-2][j];
					}
				}
				else{
					dp[i][j] = 0;
				}
			}
		}
		
		int ans = 0;
		/*
		for(int i = 0; i < y; i++){
			for(int j = 0; j < x; j++){
				cout<<dp[i][j] << " " << flush;
			}
			cout << endl;
		}
		*/
		for(int i = 0; i < x; i++){
			ans += dp[y-1][i];
			if(y-2 >= 0 && map[y-2][i] == 2){
				ans+= dp[y-2][i];
			}
		}
		
		cout << ans << endl;
	}
}