#include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	int X, Y;
	while ( cin >> X >> Y && X && Y )
	{
		vector < vector <int> > map( Y, vector <int>(X, 0) );
		vector < vector <int> > dp( Y, vector <int>(X, 0) );
		for ( int i = 0; i < Y; i++ )
		{
			for ( int j = 0; j < X; j++ )
			{
				cin >> map[i][j];
			}
		}

		for ( int i = 0; i < X; i++ )
		{
			if ( map[0][i] == 0 )
				dp[0][i] = 1;
		}

		for ( int i = 0; i < Y-1; i++ )
		{
			for ( int j = 0; j < X; j++ )
			{
				if ( map[i][j] == 2 )
				{
					if ( i+2 < Y )
					{
						if ( map[i+2][j] != 1 )
							dp[i+2][j] += dp[i][j];
					}
					else
					{
						dp[Y-1][j] += dp[i][j];
					}
				}
				if ( map[i][j] == 0 )
				{
					if ( i+1 < Y )
					{
						if ( map[i+1][j] == 2 )
						{
							dp[i+1][j] += dp[i][j];
						}
					}
				}
				for ( int k = -1; k < 2; k++ )
				{
					if ( j+k<0 || j+k>=X )
						continue;

					if ( map[i][j] == 0 && map[i+1][j+k] == 0 )
					{
						dp[i+1][j+k] += dp[i][j];
					}
				}
			}
		}

		int answer = 0;
		for ( int i = 0; i < X; i++ )
		{
			answer += dp[Y-1][i];
		}

		cout << answer << endl;

	}
	return 0;
}