#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;

struct Edge{int to,from,cost;};

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define mp make_pair
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,1,-1,-1,0};
const int dy[]={0,0,1,-1,1,-1,1,-1,0};

int c[20][20];
int r[20][20];

int main() {
	int x,y;
	for(;;){
		cin>>x>>y;
		if(x==0&&y==0)break;
		memset(c,0,sizeof(c));
		memset(r,0,sizeof(r));
		rep(i,y)rep(j,x)c[i][j+1]=in();
		rep(i,x)if(c[0][i+1]==0)r[0][i+1]=1;
		repn(i,1,y-1)repn(j,1,x){
			if(c[i][j]==0){
				if(c[i-1][j-1]==0)r[i][j]+=r[i-1][j-1];
				if(c[i-1][j]==0)r[i][j]+=r[i-1][j];
				if(c[i-1][j+1]==0)r[i][j]+=r[i-1][j+1];
				if(i>1&&c[i-2][j]==2)r[i][j]+=r[i-2][j];
			}
			if(c[i][j]==2){
				if(c[i-1][j]==0)r[i][j]+=r[i-1][j];
				if(i>1&&c[i-2][j]==2)r[i][j]+=r[i-2][j];
			}
		}
		int result=0;
		repn(i,1,x)result+=r[y-1][i];
		repn(i,1,x)if(c[y-2][i]==2)result+=r[y-2][i];
//rep(i,y){
//rep(j,x)cout<<" "<<r[i][j+1];
//cout<<endl;
//}
		cout<<result<<endl;
	}
	return 0;
}