#include<iostream>
using namespace std;
int main()
{
	int n, m;
	while (true){
		cin >> n >> m;
		if (n == 0 && m == 0){
			break;
		}
		int map[100][100] = { 0 };
		int dp[100][100] = { 0 };
		for (int i = 0; i < n; i++){
			for (int i2 = 0; i2 < m; i2++){
				cin >> map[i][i2];
			}
		}
		for (int i = 0; i < n; i++){
			if (map[0][i] == 0){
				dp[0][i] = 1;
			}
		}
		for (int i = 0; i < m-1; i++){
			for (int i2 = 0; i2 < n; i2++){
				if (map[i][i2] == 0){
					if (map[i + 1][i2] == 0 || map[i + 1][i2] == 2){
						dp[i + 1][i2] += dp[i][i2];
					}
					if (i2+1<m&&map[i + 1][i2 + 1] == 0){
						dp[i + 1][i2 + 1] += dp[i][i2];
					}
					if (i2 - 1 >= 0 && map[i + 1][i2 - 1] == 0){
						dp[i + 1][i2 - 1] += dp[i][i2];
					}
				}
				if (map[i][i2] == 2){
					if (map[i + 2][i2] == 0 || map[i + 2][i2] == 2){
						dp[i + 2][i2] += dp[i][i2];
					}
				}
			}
		}
		for (int i = 0; i < n; i++){
			if (map[m - 1][i]==2){
				dp[m + 1][i] += dp[m - 1][i];
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++){
			ans += dp[m - 1][i];
			ans += dp[m][i];
			ans += dp[m + 1][i];
		}
		cout << ans << endl;
	}
}