#include <bits/stdc++.h>

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int field[15][15];
int dp[15][15];
int x, y;

int calc_pattern()
{
	int pattern = 0;

	loop(i, 0, x)
	{
		if( field[0][i] != 1 )
		{
			dp[0][i] = 1;
		}
		else
		{
			dp[0][i] = 0;
		}
	}

	loop(i, 0, y - 1)
	{
		loop(j, 0, x)
		{
			if( field[i][j] == 0 )
			{
				if( j >= 1 && j < x - 1 )
				{
					dp[i + 1][j - 1] += field[i + 1][j - 1] == 0 ? dp[i][j] : 0;
					dp[i + 1][j    ] += field[i + 1][j    ] != 1 ? dp[i][j] : 0;
					dp[i + 1][j + 1] += field[i + 1][j + 1] == 0 ? dp[i][j] : 0;
				}
				else if( j == 0 )
				{
					dp[i + 1][j    ] += field[i + 1][j    ] != 1 ? dp[i][j] : 0;
					dp[i + 1][j + 1] += field[i + 1][j + 1] == 0 ? dp[i][j] : 0;
				}
				else if( j == x - 1 )
				{
					dp[i + 1][j - 1] += field[i + 1][j - 1] == 0 ? dp[i][j] : 0;
					dp[i + 1][j    ] += field[i + 1][j    ] != 1 ? dp[i][j] : 0;
				}
			}
			else if( field[i][j] == 1 )
			{
				dp[i][j] = 0;
			}
			else if( field[i][j] == 2 )
			{
				if( i != y - 2 )
				{
					dp[i + 2][j] += field[i + 2][j] != 1 ? dp[i][j] : 0;
				}
				else
				{
					pattern += dp[i][j];
				}
			}
		}
	}
	loop(i, 0, x)
	{
		pattern += dp[y - 1][i];
	}

	return pattern;
}

int main()
{
	int pattern;
	while( 1 )
	{
		scanf("%d%d", &x, &y);
		if( x == 0 && y == 0 )break;
		
		loop(i, 0, 15)
		{
			loop(j, 0, 15)
			{
				field[i][j] = 0;
				dp[i][j] = 0;
			}
		}
		loop(i, 0, y)
		{
			loop(j, 0, x)
			{
				field[i][j] = in();
			}
		}

		pattern = calc_pattern();
		printf("%d\n", pattern);
	}
	return (0);
}