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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;

int main()
{
	int w, h;
	while(scanf("%d%d", &w, &h), w){
		vvi field(h+1, vi(w, 0));
		rep(i, h) rep(j, w)
			scanf("%d", &field[i][j]);
		
		vvi dp(h+1, vi(w));
		rep(i, w)
			dp[0][i] = field[0][i] == 0;
		
		reep(i, 1, h+1){
			rep(j, w){
				if(field[i][j] == 1){
					dp[i][j] = 0;
				}
				else{
					if(i<h){
						const int dx[] = {-1, 0, 1};
						rep(k, 3){
							int px = j + dx[k];
							if(px<0 || w<=px || field[i-1][px] != 0 || (field[i][j]==2 && dx[k]!=0))
								continue;
							dp[i][j] += dp[i-1][px];
						}
					}
					if(i>=2 && field[i-2][j] == 2)
						dp[i][j] += dp[i-2][j];
				}
			}
		}

		int sum = 0;
		rep(i, 2) rep(j, w)
			sum += dp[h-i][j];
		printf("%d\n", sum);
	}
	return 0;
}