#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)

int main()
{
	
	while(1)
	{
		int w,h; cin >> w >> h;
		if(w == 0) return 0;
		int f[20][20]={};
		for(int i=1;i<=h;i++)
		{
			for(int j=1;j<=w;j++)
			{
				cin >> f[i][j];
			}
		}
		ll dp[20][20]={};
		for(int i=1;i<=w;i++) if(f[1][i] != 1) dp[1][i] = 1LL;
		for(int i=1;i<=h;i++)
		{
			for(int j=1;j<=w;j++)
			{
				if(!dp[i][j]) continue;
				if(f[i][j] == 0)
				{
					if(j != 1)
					{
						if(f[i+1][j-1] == 0 && i+1 <= h) dp[i+1][j-1] += dp[i][j];
					}
					if(f[i+1][j] != 1 && i+1 <= h) dp[i+1][j] += dp[i][j];
					if(j != w)
					{
						if(f[i+1][j+1] == 0 && i+1 <= h) dp[i+1][j+1] += dp[i][j];
					}
				}
				else if(f[i][j] == 2)
				{
					if(f[i+2][j] != 1 && i+2 <= h) dp[i+2][j] += dp[i][j];
				}
			}
		}
		ll res = 0;
		for(int i=1;i<=w;i++) if(f[h-1][i] == 2) res += dp[h-1][i];
		for(int i=1;i<=w;i++) res += dp[h][i];
		cout << res << endl;
	}
}