#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++){
			if(map[0][i] == 0){
				dp[0][i] = 1;
			}
			else{
				dp[0][i] = 0;
			}
		}
		for(int i = 1; i < y; i++){
			for(int j = 0; j < x; j++){
				//ツ配ツ療アツ外ツアツクツセツスツづーツづ「ツづ淞づヲツつ、
				if(j == 0){
					if(map[i][j] == 1){
						dp[i][j] = 0;
					}
					else if(map[i][j] == 0){
						if(map[i-1][j] == 2 ||map[i-1][j+1] == 2){
							if(map[i-1][j] == 2 || map[i-1][j-1] == 2 || map[i-1][j+1] == 2){
								if(map[i-1][j] == 2){
									dp[i][j] = dp[i-1][j+1];
								}
								if(map[i-1][j+1] == 2){
									dp[i][j] = dp[i-1][j];
								}
							}
						}
						else{
							dp[i][j] = dp[i-1][j] + dp[i-1][j+1];
						}
						if(map[i-2][j] == 2){
							dp[i][j] += dp[i-2][j];
						}
					} 
					else if(map[i][j] == 2){
						dp[i][j] = dp[i-1][j];
					}
				}
				//ツつサツづェツ暗按外
				else{
					if(map[i][j] == 0){
						if(map[i-1][j] == 2 || map[i-1][j-1] == 2 || map[i-1][j+1] == 2){
							if(map[i-1][j] == 2){
								dp[i][j] = dp[i-1][j+1] + dp[i-1][j-1];
							}
							if(map[i-1][j-1] == 2){
								dp[i][j] = dp[i-1][j] + dp[i-1][j+1];
							}
							if(map[i-1][j+1] == 2){
								dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
							}
							if(map[i-1][j] == 2 && map[i-1][j+1] == 2){
								dp[i][j] = dp[i-1][j-1];
							}
							if(map[i-1][j] == 2 && map[i-1][j-1] == 2){
								dp[i][j] = dp[i-1][j+1];
							}
							if(map[i-1][j+1] == 2 && map[i-1][j-1] == 2){
								dp[i][j] = dp[i-1][j];
							}
							if(map[i-1][j+1] == 2 && map[i-1][j] == 2 && map[i-1][j-1] == 2){
								dp[i][j] = 0;
							}
						}
						else{
							dp[i][j] = dp[i-1][j] + dp[i-1][j-1] + dp[i-1][j+1];
						}
						if(map[i-2][j] == 2){
							dp[i][j] += dp[i-2][j];
						}
					}
					else if(map[i][j] == 1){
						dp[i][j] = 0;
					}
					else if(map[i][j] == 2){
						dp[i][j] = dp[i-1][j];
						if(map[i-2][j] == 2){
							dp[i][j] += dp[i-2][j];
						}
					}
				}
			}
		}
		
		int ans = 0;
		
		for(int i = 0; i < x; i++){
			ans += dp[y-1][i];
		}
		
		for(int i = 0; i < x; i++){
			if(map[y-2][i] == 2){
				ans+= dp[y-2][i];
			}
		}
		
		cout << ans << endl;
	}
}