#include <iostream>
#include <vector>
#include <array>

using namespace std;

int main()
{

    int height, width;

    while (cin >> width >> height) {
        if (height == 0 && width == 0) break;

        vector<vector<int>> field(height + 1, vector<int>(width + 2));

        // input
        for (int y = 0; y < height; ++y) {
            for (int x = 1; x < width + 1; ++x) {
                cin >> field.at(y).at(x);
            }
        }

        vector<vector<int>> dp(height + 1, vector<int>(width + 2));

        for (int x = 1; x < width + 1; ++x) {
            if (field.at(0).at(x) != 1) {
                dp.at(0).at(x) = 1;
            }
        }

        // dp
        array<int, 3> dx = {-1, 0, 1};


        for (int y = 0; y < height - 1; ++y) {
            for (int x = 1; x < width + 1; ++x) {
                switch (field.at(y).at(x)) {
                    case 0:
                        for (int i = 0; i < 3; ++i) {
                            // ?????????1??§???????????¨????????????
                            // ?¬???????2????????????????????????????????????
                            if (field.at(y + 1).at(x + dx.at(i)) != 1) {
                                switch (i) {
                                    case 1:
                                        dp.at(y + 1).at(x + dx.at(i)) += dp.at(y).at(x);
                                        break;
                                    default:
                                        if (field.at(y + 1).at(x + dx.at(i)) != 2) {
                                            dp.at(y + 1).at(x + dx.at(i)) += dp.at(y).at(x);
                                        }
                                        break;
                                }
                            }
                        }
                        break;
                    case 1:
                        break;
                    case 2:
                        // y = height - 2??§2????????£?????´????????????
                        if ( y + 2 >= height) {
                            dp.at(y + 1).at(x) += dp.at(y).at(x);
                        }
                        else {
                            dp.at(y + 2).at(x) += dp.at(y).at(x);
                        }
                        break;
                }
            }
        }

        int ans = 0;

        for (int x = 1; x < width + 1; ++x) {
            ans += dp.at(height - 1).at(x);
        }

        cout << ans << endl;
    }

    return 0;
}