#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
	int w, h;
	while(scanf("%d%d", &w, &h), w){
		vvi field(h, vi(w));
		rep(i, h){
			rep(j, w){
				scanf("%d", &field[i][j]);
			}
		}
		
		vvi dp(h, vi(w, 0));
		rep(i, w){
			dp[0][i] = !field[0][i];
		}
		
		reep(i, 1, h){
			rep(j, w){
				if(field[i][j] == 1)
					continue;
				
				if(i >= 2){
					dp[i][j] += field[i-2][j] == 2 ? dp[i-2][j] : 0;
				}
				reep(k, field[i][j] == 0 ? -1 : 0, field[i][j] == 0 ? 2 : 1){
					int px = j + k;
					if(px < 0 || w <= px)
						continue;
					if(field[i-1][px] != 0)
						continue;
					dp[i][j] += dp[i-1][px];
				}
			}
		}
		
		int sum = 0;
		rep(i, w){
			sum += dp[h-1][i];
			if(h > 1)
				sum += field[h-2][i] == 2 ? dp[h-2][i] : 0;
		}
		printf("%d\n", sum);
	}
	return 0;
}