#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << p.first << " " << p.second;return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if (it != v.begin())os << " ";os << *it;
  }return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;




int a[20][20], dp[20][20];
int dy[] = {1, 1, 1}, dx[] = {-1, 0, 1};
void init(){
	rep(i,20)rep(j,20)dp[i][j] = 0;
}

signed main(){
	while(1){
		int h, w;
		cin >> w >> h;
		if(w == 0 and h == 0)break;
		rep(i,h)rep(j,w)cin >> a[i][j];
		init();
		rep(i,w)if(a[0][i] == 0)dp[0][i] = 1;
		rep(i,h){
			rep(j,w){
				if(a[i][j] >= 1)continue;
				if(i == h-1){
					dp[i+1][j] += dp[i][j];
					continue;
				}
				rep(k,3){
					int yy = i+dy[k], xx = j+dx[k];
					if(xx < 0 or w <= xx)continue;
					while(k == 1 and a[yy][xx] == 2)yy += 2;
					if(a[yy][xx] == 2)continue;
					dp[yy][xx] += dp[i][j];
				}
			}
		}
		int ans = 0;
		repi(i,h,20)rep(j,w)ans += dp[i][j];
		cout << ans << endl;
	}
	return 0;
}





