#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int x, y;
	while (scanf("%d %d", &x, &y), x | y)
	{
		int topo[16][15 + 2];
		memset(topo, 0, sizeof(topo));
		for (int i = 0; i < y; ++i)
			for (int j = 1; j <= x; ++j)
				scanf("%d", &topo[i][j]);

		int dp[16][15 + 2];
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= x; ++i)
			dp[0][i] = 1;

		for (int i = 0; i < y-1; ++i)
		{
			for (int j = 1; j <= x; ++j)
			{
				if (topo[i][j] == 0 && i < y-1)
				{
					for (int k = -1; k <= 1; ++k)
						if (topo[i+1][j+k] != 1 && (topo[i+1][j+k] == 0 || k == 0))
							dp[i+1][j+k] += dp[i][j];
				}
				else if (topo[i][j] == 2 && topo[i+2][j] != 1)
					dp[i+2][j] += dp[i][j];
			}
		}
		int ans = 0;
		for (int i = y-1; i <= y; ++i)
			for (int j = 1; j <= x; ++j)
				ans += dp[i][j];
		printf("%d\n", ans);
	}

	return 0;
}