#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int d[21][21];
ll dp[21][21];
int w, h;

bool isOutofRange(int x, int y){
	if(x < 0 || x >= w || y < 0) return true;
	return false;
}

int main(){
	while(cin>>w>>h && w && h){
		rep(i, 21) rep(j, 21) dp[i][j] = 0LL, d[i][j]=0;;
		rep(i, h) rep(j, w) cin>>d[i][j];
		for(int i = 0; i < w; i++){
			if(d[0][i] != 1) dp[0][i] = 1LL;
		}

		for(int i = 0; i < h-1; i++){
			for(int j = 0; j < w; j++){
				if(d[i][j]!=0) continue;
				for(int k = 0; k < 3; k++){
					int nx = j + dx[k], ny = i+1;
					if(isOutofRange(nx, ny)) continue;
					if(d[ny][nx] == 0) {
						dp[ny][nx] += dp[i][j];
					}
				}
				if(d[i+1][j]==2) dp[i+2][j]+=dp[i][j];
			}
		}
		ll ans = 0ll;
		rep(i, w){
			ans += dp[h-1][i];
			ans += dp[h][i];
		}
		cout<<ans<<endl;
		// rep(i, h) {
		// 	rep(j, w){
		// 		cout<<dp[i][j]<<" ";
		// 	}
		// 	cout<<endl;
		// }
	}
	
}