#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <complex>

#define EPS	1.0e-10
#define rep(idx, max)	for(int idx = 0, idx##Max = max; idx < idx##Max; idx ++)
#define rrep(idx, min, max)	for(int idx = min, idx##Max = max; idx < idx##Max; idx ++)
#define erep(idx, min, max)	for(int idx = min, idx##Max = max; idx <= idx##Max; idx ++)

#define rev(idx, max)	for(int idx = max - 1; idx >= 0; idx --)

typedef unsigned int UINT;
typedef std::vector<int>	VEC;
typedef struct _POINT
{
	int x, y;
	_POINT(){}
	_POINT(int _x, int _y): x(_x), y(_y){}
} POINT;

enum
{
	JMP = 2,
	BLK = 1,
	FLOOR = 0, 
};

#define MAX_N	32

int g_width, g_height;
int g_map[MAX_N][MAX_N];
int g_cache[MAX_N][MAX_N];

void	PrintCache()
{
	rep(y, g_height + 2)
	{	rep(x, g_width + 2)	{	::printf("%2d|", g_cache[y][x]);	}	::puts("");	}
	::puts("");
}

int	Solve()
{
	erep(y, 1, g_height) erep(x, 1, g_width)
	{
	//	::PrintCache();
		switch (g_map[y][x])
		{
		case BLK:	break;
		case FLOOR:
			erep(dx, -1, +1)
			{
				int &fieldn = g_map[y + 1][x + dx];
				if (fieldn == BLK || (fieldn == JMP && dx != 0)) { continue; }
				g_cache[y + 1][x + dx] += g_cache[y][x];
			}
			break;
		case JMP:
			if (g_map[y + 2][x] != BLK) { g_cache[y + 2][x] += g_cache[y][x]; }
			break;
		}
	}

	int count = 0;
	erep(x, 1, g_width)
	{
		count += g_cache[g_height + 1][x] + g_cache[g_height][x];
	}
	return(count);
}

void	PrintMap()
{
	rep(y, MAX_N)
	{	rep(x, MAX_N)	{	::printf("%2d|", g_map[y][x]);	}	::puts("");	}
	::puts("");
}

void	InitMap()
{
//	::memset(g_map, BLK, sizeof(g_map));
	rep(y, MAX_N) rep(x, MAX_N) { g_map[y][x] = BLK; }
	erep(y, 1, g_height) erep(x, 1, g_width)	{	std::cin >> g_map[y][x];	}
}

void	InitCache()
{
	::memset(g_cache, 0, sizeof(g_cache));
//	rep(y, MAX_N) rep(x, MAX_N) { g_cache[y][x] = -1; }
	erep(x, 1, g_width) { g_cache[1][x] = 1; }
}

int main(int nArgs, char **lplpszArgs)
{
	while (std::cin >> g_width >> g_height, g_width)
	{
		InitMap();
		InitCache();
	//	PrintMap();
		::printf("%d\n", ::Solve());
	}
}