#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		vvi field(h+1,vi(w));
		rep(i,h) rep(j,w)
			cin>>field[i][j];
		
		vvi dp(h+1,vi(w));
		rep(i,w)
			if(field[0][i]!=1)
				dp[0][i]=1;
		rep(i,h-1){
			rep(j,w){
				if(field[i][j]==1){
					dp[i][j]=0;
					continue;
				}
				if(field[i][j]==2 && field[i+2][j]!=1){
					dp[i+2][j]+=dp[i][j];
					continue;
				}
				if(field[i+1][j]==2)
					dp[i+1][j]+=dp[i][j];
				for(int k=-1;k<=1;k++)
					if(0<=j+k && j+k<w && field[i+1][j+k]==0)
						dp[i+1][j+k]+=dp[i][j];
			}
		}
		ll res=0;
		repi(i,h-1,h+1) rep(j,w)
			if(field[i][j]!='1')
				res+=dp[i][j];
		cout<<res<<endl;
	}
	
	return 0;
}