#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(){
	while(true){
		int maxX,maxY;
		cin >> maxX >> maxY;			if(!maxX&&!maxY) return 0;

		int tizu[maxX+2][maxY+2];
		FOR(y,0,maxY+2){
			FOR(x,0,maxX+2){
				if(x==0||x==maxX+1||y==0||y==maxY+1){tizu[x][y]=1;continue;};
				cin >> tizu[x][y];
			}
		}

		int dp[maxX+2][maxY+2];
		FOR(y,0,maxY+2){
			FOR(x,0,maxY+2){
				dp[x][y]=0;
				if(x==0||x==maxX+1){
					continue;
				}
				if(y==0){
					continue;
				}
				if(y==1){
					if(tizu[x][y]==0) dp[x][y]+=1;
					continue;
				}
				if(y==maxY+1){
					if(tizu[x][y-1]==0) dp[x][y]+=dp[x][y-1];
					if(tizu[x][y-1]==2) dp[x][y]+=dp[x][y-1];
					if(tizu[x][y-2]==2) dp[x][y]+=dp[x][y-2];
					continue;
				}
				if(tizu[x][y]==0){
					if(tizu[x-1][y-1]==0) dp[x][y]+=dp[x-1][y-1];
					if(tizu[x][y-1]==0)   dp[x][y]+=dp[x][y-1];
					if(tizu[x+1][y-1]==0) dp[x][y]+=dp[x+1][y-1];
					if(tizu[x][y-2]==2)   dp[x][y]+=dp[x][y-2];
					continue;
				}
				if(tizu[x][y]==1){
					continue;
				}
				if(tizu[x][y]==2){
					if(tizu[x][y-1]==0) dp[x][y]+=dp[x][y-1];
					if(tizu[x][y-2]==2) dp[x][y]+=dp[x][y-2];
					continue;
				}
			}
		}


		int res = 0;
		FOR(x,1,maxX+1){ res += dp[x][maxY+1];};
		cout << res << endl;

	}
}