#include <iostream>
using namespace std;


int main() {
    int field[16][17], pattern[17][17];
    int X, Y, i, j, k;

    while ((cin >> X >> Y) && X) {
        for (i = 1; i <= Y; i++) {
            field[i][0] = field[i][X+1] = 0;
            for (j = 1; j <= X; j++) {
                cin >> field[i][j];
            }
        }

        for (i = 2; i <= Y+1; i++) {
            for (j = 0; j <= X + 1; j++) {
                pattern[i][j] = 0;
            }
        }
        for (j = 1; j <= X; j++) {
            pattern[1][j] = field[1][j] == 0;
        }

        for (i = 1; i < Y; i++) {
            for (j = 1; j <= X; j++) {
                switch (field[i][j]) {
                    case 0:
                    for (k = -1; k <= 1; k++) {
                        switch (field[i+1][j+k]) {
                            case 0:
                            pattern[i+1][j+k] += pattern[i][j];
                            break;
                            case 2:
                            if (k == 0) {
                                pattern[i+1][j+k] += pattern[i][j];
                            }
                            break;
                            default: break;
                        }
                    }
                    break;
                    case 2:
                    pattern[i+2][j] += pattern[i][j];
                    break;
                    default: break;
                }
            }
        }
        /*
        for (i = 1; i <= Y; i++) {
            for (j = 1; j <= X; j++) {
                cout << " " << pattern[i][j];
            }
            cout << endl;
        }
        cout << endl;
        */
        int sum = 0;
        for (i = Y; i <= Y + 1; i++) {
            for (j = 1; j <= X; j++) {
                sum += pattern[i][j];
            }
        }
        cout << sum << endl;
    }
    return 0;
}