#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int dx[] = {-1,0,1},dy[] = {-1,-1,-1};
int main(){
	int x,y;
	while(cin >> x >> y,x,y){
		int dp[20][20] = {{0}};
		int field[20][20] = {{0}};
		for(int i = 1; i <= y; i++){
			for(int j = 1; j <= x; j++){
				cin >> field[i][j];
			}
		}
		for(int i = 1; i <= y+2; i++){
			for(int j = 1; j <= x; j++){
				if(i == 1 && field[i][j] == 0){
					dp[i][j] = 1;
					continue;
				}
				if(i <= y){
					for(int k = 0; k < 3; k++){
						int px = j+dx[k],py = i+dy[k];
						if(field[i][j] == 0){
							if(field[py][px] == 0)dp[i][j] += dp[py][px];
							else if(field[py][px] == 2)continue;
						}
						else if(field[i][j] == 2){
							if(k == 1)dp[i][j] += dp[py][px];
						}
						else if(field[i][j] == 1)continue;
					}
				}
				if(i > 3){
					int px = j,py = i - 2;
					if(field[py][px] == 2){
						dp[i][j] += dp[py][px];
					}
				}
			}
		}
		int sum = 0;
		for(int i = 1; i <= x; i++){
			sum += dp[y][i];
			sum += dp[y+1][i];
			sum += dp[y+2][i];
		}
		cout << sum << endl;
	}
	return 0;
}