#include<iostream>
using namespace std;

int main(){
	int x,y;
	while(cin>>x>>y,x){
		int D[16][16],P[16][16],ans=0;
		for(int i=0;i<256;i++)P[i/16][i%16]=0;
		for(int i=0;i<y;i++)for(int j=0;j<x;j++)cin>>D[i][j];
		for(int i=0;i<x;i++)if(!D[0][i])P[0][i]=1;
		for(int i=0;i<y-1;i++){
			for(int j=0;j<x;j++){
				if(!D[i][j]){
					P[i+1][j]+=P[i][j];
					if(j>0&&D[i+1][j-1]!=2)P[i+1][j-1]+=P[i][j];
					if(j<x-1&&D[i+1][j+1]!=2)P[i+1][j+1]+=P[i][j];
				}
				if(D[i][j]==2){
					if(i+2>y-1)ans+=P[i][j];
					else P[i+2][j]+=P[i][j];
				}
			}
		}
		for(int i=0;i<x;i++){
			if(D[y-1][i]!=1)ans+=P[y-1][i];
		}
		cout<<ans<<endl;
	}
}