#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
using namespace std;
int main(){
	int X,Y,c[15][15],land[15][15],ans;
	while(cin>>X>>Y,X){
		rep(i,Y)rep(j,X)cin>>land[i][j],c[i][j]=i==0&&land[i][j]!=1;
		rep(i,Y-1)rep(j,X)if(land[i+1][j]!=1){
			if(land[i+1][j]==2)c[i+1][j]+=land[i][j]==0?c[i][j]:0;
			else rep(d,3)if(ck(j+d-1,X)&&land[i][j+d-1]==0)
			c[i+1][j]+=c[i][j+d-1];
			if(i>0&&land[i-1][j]==2)c[i+1][j]+=c[i-1][j];
		}
		ans=0;
		rep(i,X)ans+=c[Y-1][i]+(Y>1&&land[Y-2][i]==2?c[Y-2][i]:0);
		cout<<ans<<endl;
	}
	return 0;
}