#include <iostream>
#include <vector>
#include <cstring>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int a[16][16];
int count = 0;
int n,m;

void dfs(int y,int x)
{
	if(y > m-1)
	{
		return;
	}

	if(a[y][x] == 0)
	{
		if(y == m-1)
		{
			count++;
			return;
		}
		if(x-1 >= 0 && y+1 < m)
		{
			if(a[y+1][x-1] != 2)
			{
				dfs(y+1,x-1);
			}
		}
		if(y+1 < m)
		{
			dfs(y+1,x);
		}
		if(x+1 < n && y+1 < m)
		{
			if(a[y+1][x+1] != 2)
			{
				dfs(y+1,x+1);
			}
		}
		return;
	}
	else if(a[y][x] == 1)
	{
		return;
	}
	else if(a[y][x] == 2)
	{
		if(y == m-2)
		{
			count++;
			return;
		}
		else if(y == m-1)
		{
			count++;
			return;
		}
		else
		{
			dfs(y+2,x);
		}
	}
}

int main()
{
	while(cin >> n >> m)
	{
		if(n == 0 && m == 0)
		{
			break;
		}

		memset(a,0,sizeof(a));
		rep(i,n)
		{
			rep(j,m)
			{
				cin >> a[i][j];
			}
		}
		count = 0;
		rep(i,n) dfs(0,i);

		cout << count << endl;
	}
	return 0;
}