# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int main()
{
	const int M = 20;
	while (true)
	{
		int x, y;
		int a[M][M];

		cin >> x >> y;
		if (!x&&!y)break;

		FOR(i, M)FOR(j, M)
		{
			a[i][j] = 1;
		}

		FORI(i, 1, y + 1)FORI(j, 1, x + 1)
		{
			cin >> a[i][j];
		}
		FORI(i, 1, x + 1)
		{
			a[y + 1][i] = 0;
		}
		int ans[M][M] = {};
		FORI(i, 1, x + 1)
		{
			if (a[1][i] == 0)ans[1][i] = 1;
		}
			
		FORI(i, 1, y)
		{
			FORI(j, 1, x + 1)
			{
				switch (a[i][j])
				{
				case 0:
					FORI(k, -1, 1 + 1)
					{
						if (a[i+1][j + k] == 0)
						{
							ans[i+1][j + k] += ans[i][j];
						}
					}
					if (a[i + 1][j] == 2)
					{
						ans[i + 1][j] += ans[i][j];
					}
					break;
				case 1:
					ans[i][j] = 0;
					break;
				case 2:
					if (a[i + 2][j] != 1)
					{
						ans[i + 2][j] += ans[i][j];
					}
					break;
				}
			}
		}

		int ANS = 0;
		FORI(i, 1, x + 1)
		{
			ANS += ans[y][i]+ans[y+1][i];
		}
		cout << ANS << endl;



	}
}