#include <bits/stdc++.h>
using namespace std;

int w, h;
vector< vector< int > > field, cnt;

int rec(int y, int x, int px){
	if(x < 0 || x > w - 1) return 0;
	if(y >= h) return 1;
	if(cnt[y][x] != -1) {
		if(field[y][x] == 2 && px != x) return 0;
		return cnt[y][x];
	}
	
	if(field[y][x] == 1) return cnt[y][x] = 0;
	else if(field[y][x] == 0) return cnt[y][x] = rec(y + 1, x - 1, x) + rec(y + 1, x, x) + rec(y + 1, x + 1, x);
	else{
		cnt[y][x] = rec(y + 2, x, x);
		
		if(px == x) return cnt[y][x];
		else return 0;
	}
}

int main(){
	
	while(cin >> w >> h, w){
		field.resize(h);
		cnt.resize(h);
		for(int i = 0; i < h; ++i){
			field[i].resize(w);
			cnt[i].resize(w);
			for(int j = 0; j < w; ++j){
				cin >> field[i][j];
				cnt[i][j] = -1;
			}
		}
		
		for(int i = 0; i < w; ++i){
			cnt[h - 1][i] = (field[h - 1][i] == 1 ? 0 : 1);
		}
		
		int sum = 0;
		for(int i = 0; i < w; ++i){
			sum += rec(0, i, i);
		}
		
		cout << sum << endl;
	}
	
	return 0;
}