#include <bits/stdc++.h>

#define all(a)  (a).begin(),(a).end()
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define exist(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define range(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define rep(i,n)  range(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef vector<int> vi;
typedef long long ll;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int w,h;
int course[20][20];
ll dp[20][20];

int main(void){
	while(cin >> w >> h,w|h){
		clr(dp,0);
		rep(i,h)rep(j,w) cin >> course[i][j];
		rep(i,w) if(course[0][i]==0) dp[0][i]=1LL;
		rep(i,h-1)rep(j,w){
			if(course[i][j]==2&&course[i+2][j]!=1) dp[i+2][j]+=dp[i][j];
			if(course[i][j]) continue;
			for(int nj=j-1;nj<=j+1;++nj){
				if(nj<0||w<=nj) continue;
				if(course[i+1][nj]==1) continue;
				if(j!=nj&&course[i+1][nj]==2) continue;
				dp[i+1][nj]+=dp[i][j];
			}
		}
		/*
		rep(i,h+1){
			rep(j,w) cerr << dp[i][j] << " ";
			cerr << endl;
		}*/
		ll ans=0LL;
		range(i,h-1,h+1)rep(j,w) ans+=dp[i][j];
		cout << ans << endl;
	}
	return 0;
}