#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 < m; i++){
			for (int i2 = 0; i2 < n; 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; i++){
			for (int i2 = 0; i2 < n; i2++){
				if (map[i][i2] == 0){
					for (int i3 = -1; i3 <= 1; i3++){
						if (i2 + i3 >= 0 && i2 + i3 < n && (map[i + 1][i2 + i3] == 0 || i3 == 0 && map[i + 1][i2 + i3] == 2)&&(i<m-1||i3==0)){
							dp[i + 1][i2+i3]  += dp[i][i2];
						}
					}	
				}
				else if (map[i][i2] == 2){
							dp[i + 2][i2] += dp[i][i2];
					}
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++){
			ans += dp[m][i];
			ans += dp[m+1][i];
		}
		cout << ans << endl;
	}
}