#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#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
 
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<double, int> pdi;
typedef pair<ll, ll> pll;
 

 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	ll l;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	ll nextLong(){
		scanf("%lld", &l);
		return l;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

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

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

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

int main(){
	while(1){
		w = in.nextInt();
		h = in.nextInt();
		if(w == 0 && h == 0) break;
		rep(i, 30) rep(j, 30) d[i][j] = 0, dp[i][j] = 0LL;
		rep(i, h) rep(j, w){
			d[i][j] = in.nextInt();
		}
		rep(i, w) if(d[0][i]!=1) dp[0][i] = 1;
		for(int i = 0; i < h-1; i++){
			for(int j = 0; j < w; j++){
				if(d[i][j]==0){
					for(int k = 0; k < 3; k++){
						int nx = j + dx[k], ny = i + dy[k];
						if(d[ny][nx]==0){
							dp[ny][nx] += dp[i][j];
						}
					}
					if(d[i + 1][j] == 2){
						dp[i + 3][j] += dp[i][j];
					}
				}
				else if(d[i][j]==2){
					dp[i+2][j] += dp[i][j];
				}
			}
		}
		// for(int i = 0; i < h; i++){
		// 	for(int j = 0; j < w; j++){
		// 		cout<<" "<<d[i][j];
		// 	}
		// 	cout<<endl;
		// }
		// cout<<endl;
		// for(int i = 0; i < h + 1; i++){
		// 	for(int j = 0; j < w; j++){
		// 		cout<<" "<<dp[i][j];
		// 	}
		// 	cout<<endl;
		// }
		ll ans = 0LL;
		for(int i = 0; i < w; i++){
			ans += dp[h][i];
			ans += dp[h-1][i];
			ans += dp[h+1][i];
			ans += dp[h+2][i];
		}
		cout<<ans<<endl;
	}
}