#include <bits/stdc++.h>
using namespace std;

constexpr int MAX = 1000001;

int main() {
    int X, Y;
    while(cin >> X >> Y, X) {
        vector<vector<int>> c(Y+1, vector<int>(X));
        for(int i=0; i<Y; ++i) {
            for(int j=0; j<X; ++j) {
                cin >> c[i][j];
            }
        }
        vector<vector<int>> dp(Y+1, vector<int>(X));
        for(int i=0; i<X; ++i) {
            dp[0][i] = c[0][i] == 0;
        }
        for(int i=0; i<Y-1; ++i) {
            for(int j=0; j<X; ++j) {
                if(c[i][j] == 1) {
                    continue;
                } else if(c[i][j] == 2) {
                    dp[i+2][j] += dp[i][j];
                } else {
                    int dx[3] = {-1, 0, 1};
                    for(int k=0; k<3; ++k) {
                        int nx = j + dx[k];
                        if(nx < 0 || X <= nx || dx[k] != 0 && c[i+1][nx] == 2) {
                            continue;
                        }
                        dp[i+1][nx] += dp[i][j];
                    }
                }
            }
        }
        int res = 0;
        for(int i=0; i<2; ++i) {
            for(int j=0; j<X; ++j) {
                if(c[Y-1+i][j] != 1) {
                    res += dp[Y-1+i][j];
                }
            }
        }
        cout << res << endl;
    }
}
