#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    enum { TREE = 1, JUMP = 2 };
    int x, y;
    while (cin >> x >> y, x) {
        vector<vector<int>> field(y, vector<int>(x));
        for (auto &v: field) for (int &vi: v) cin >> vi;
        vector<vector<int>> dp(y + 1, vector<int>(x, 0));
        for (int j = 0; j < x; j++) dp[0][j] = field[0][j] == 0;
        for (int i = 0; i < y - 1; i++) for (int j = 0; j < x; j++) {
            for (int k: {-1, 0, 1}) if (j + k >= 0 && j + k < x) {
                int ni = i + 1, nj = j + k;
                if (k == 0) {
                    if (field[i][j] == JUMP) ni++;
                } else {
                    if (field[i][j] == JUMP || field[ni][nj] == JUMP) continue;
                }
                if (ni < y && field[ni][nj] == TREE) continue;
                dp[ni][nj] += dp[i][j];
            }
        }
        int ans = 0;
        for (int j = 0; j < x; j++) ans += dp[y - 1][j] + dp[y][j];
        cout << ans << endl;
    }
    return 0;
}
