#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int X, Y;

    while (cin >> X >> Y, X || Y) {
        int grid[Y + 2][X + 2];

        // 0: 移動可能 1: 障害物がある 2: ジャンプ台がある
        for (int i = 0; i <= Y + 1; ++i) {
            for (int j = 0; j <= X + 1; ++j) {
                if (i == 0 || j == 0 || j == X + 1)
                    grid[i][j] = 1;
                else if (i == Y + 1)
                    grid[i][j] = 0;
                else
                    cin >> grid[i][j];
            }
        }

        int cnt[Y + 2][X + 2];

        memset(cnt, 0, sizeof(cnt));
        for (int i = 1; i <= X; ++i)
            if (grid[1][i] != 1)
                cnt[1][i] = 1;

        for (int i = 1; i < Y; ++i) {
            for (int j = 1; j <= X; ++j) {
                if (grid[i][j] == 0) {
                    for (int k = -1; k <= 1; ++k)
                        if (grid[i + 1][j + k] == 0 || (k == 0 && grid[i + 1][j + k] == 2))
                            cnt[i + 1][j + k] += cnt[i][j];
                }
                else if (grid[i][j] == 2 && grid[i + 2][j] != 1)
                    cnt[i + 2][j] += cnt[i][j];
            }
        }

        int ans = 0;
        for (int i = 1; i <= X; ++i)
            ans += cnt[Y][i] + cnt[Y + 1][i];

        cout << ans << endl;
    }


    return 0;
}