// 0203
#include <iostream>
#include <vector>
using namespace std;

int main(){
	while(1){
		int X, Y, c;
		vector<vector<int> > grid, count;
	
		cin>>X>>Y;
		if((X == 0) && (Y == 0))
			break;

		grid.resize(X+2);
		for(int i=0;i<X+2;i++)
			grid[i].resize(Y+2);

		for(int j=0;j<Y+2;j++){
			for(int i=0;i<X+2;i++){
				if((i == 0) || (i == X+1) || (j == 0) || (j == Y+1)){
					grid[i][j] = 1;
				}else{
					cin>>c;
					grid[i][j] = c;
				}
			}
		}

		count.resize(X+2);
		for(int i=0;i<X+2;i++)
			count[i].resize(Y+2);

		for(int i=0;i<X+2;i++)
			for(int j=0;j<Y+2;j++)
				count[i][j] = 0;

		for(int i=1;i<=X;i++)
			if(grid[i][1] == 0)
				count[i][1]++;

		for(int j=2;j<=Y;j++){
			for(int i=1;i<=X;i++){
				if(grid[i][j] == 1){
					continue;
				}else if(grid[i][j] == 2){
					if(grid[i][j-1] != 2)
						count[i][j] += count[i][j-1];
					if(grid[i][j-2] == 2)
						count[i][j] += count[i][j-2];
				}else{
					for(int k=-1;k<=1;k++)
						if(grid[i+k][j-1] != 2)
							count[i][j] += count[i+k][j-1];
					if(grid[i][j-2] == 2)
						count[i][j] += count[i][j-2];
				}
			}
		}

		int ans = 0;
		for(int i=1;i<=X;i++){
			ans += count[i][Y];
			if(grid[i][Y-1] == 2)
				ans += count[i][Y-1];
		}
		
		cout<<ans<<endl;
	}
	return 0;
}