#include<iostream>
#include<stack>

int field[15][15];
int w,h;
int dfs(int x0,int y0);

int main()
{
	while(1)
	{
		std::cin>>w>>h;
		if(w==0&&h==0)break;
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				std::cin>>field[x][y];
			}
		}
		
		int count=0;
		for(int x=0;x<w;x++)
		{
			if(field[x][0]==0)
			{
				count+=dfs(x,0);
			}
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

int dfs(int x0,int y0)
{
	std::stack<std::pair<int,int> > stk;
	int count=0;
	stk.push(std::pair<int,int>(x0,y0));
	while(!stk.empty())
	{
		int x=stk.top().first,y=stk.top().second;
		
		stk.pop();
		
		if(y>=h-1)
		{
			count++;
		}
		else
		{
			if(field[x][y]==2)
			{
				stk.push(std::pair<int,int>(x,y+2));
			}
			else if(field[x][y]==0)
			{
				if(x>0&&field[x-1][y+1]==0){stk.push(std::pair<int,int>(x-1,y+1));}
				if(x<w-1&&field[x+1][y+1]==0){stk.push(std::pair<int,int>(x+1,y+1));}
				if(field[x][y+1]!=1){stk.push(std::pair<int,int>(x,y+1));}
			}
		}
	}
	return count;
}