#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

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

int main(){
	
	while(true){
		int W, H;
		cin >> W >> H;
		if(W == 0){
			break;
		}
		int F[20][20];
		for(int i = 0; i < H; i++){
			for(int j = 1; j <= W; j++){
				cin >> F[i][j];
			}
		}
		long long int DP[20][20] = {};
		for(int i = 1; i <= W; i++){
			DP[0][i] = 1;
		}
		for(int i = 0; i < H - 1; i++){
			for(int j = 1; j <= W; j++){
				if(F[i][j] == 0){
					if(F[i + 1][j - 1] == 0){
						DP[i + 1][j - 1] += DP[i][j];
					}
					if(F[i + 1][j + 1] == 0){
						DP[i + 1][j + 1] += DP[i][j];
					}
					DP[i + 1][j] += DP[i][j];
				}else if(F[i][j] == 2){
					DP[i + 2][j] += DP[i][j];
				}
			}
		}
		long long int ans = 0;
		for(int i = 1; i <= W; i++){
			if(F[H - 1][i] != 1){
				ans += DP[H - 1][i];
			}
			ans += DP[H][i];
		}
		cout << ans << endl;
	}
	
	return 0;
}

