#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
int dp[20][20];

int saiki(vector< vector<int> > &m,int x,int y){
    if(dp[y][x] >= 0) return dp[y][x];
    if(y >= m.size()) return dp[y][x] = 1;
    if(m[y][x] == 1) return dp[y][x] = 0;
    int ret = 0;
    if(m[y][x] == 2) y++;
    else{
	if(x>0 && y+1<m.size() && m[y+1][x-1] == 0) ret += saiki(m , x-1,y+1);
	if(x+1<m[0].size() && y+1<m.size() && m[y+1][x+1] == 0) ret += saiki(m,x+1,y+1);
    }
    ret += saiki(m,x,y+1);
    return dp[y][x] = ret;
} 

int main(){
    while(true){
	int x,y;
	cin >> x >> y;
	if(x == 0 && y== 0) break;
	vector< vector<int> > m(y,vector<int>(x,0));
	memset(dp,-1,sizeof(dp));
	REP(i,y)REP(j,x)cin >> m[i][j];
	int ans = 0;
	REP(i,x){
	    ans += saiki(m,i,0);
	}
	cout << ans << endl;
    }
    return 0;
}