#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <climits>

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;
typedef pair<int,int> pii;

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, 0));
		rep(i, w)
			dp[0][i] = field[0][i] == 0;
		
		rep(i, h-1){
			rep(j, w){
				if(field[i][j] == 0){
					const int dx[] = {-1, 0, 1};
					rep(k, 3){
						int px = j + dx[k];
						if(px<0 || w<=px || field[i+1][px] == 1 || (dx[k]!=0 && field[i+1][px]==2))
							continue;
						dp[i+1][px] += dp[i][j];
					}
				}
				else if(field[i][j] == 2){
					if(i+1<h && field[i+2][j] != 1)
						dp[i+2][j] += dp[i][j];
				}
			}
		}
		
		int sum = 0;
		rep(i, 2) rep(j, w)
			sum += dp[h-i][j];
		printf("%d\n", sum);
	}
	return 0;
}