#include <iostream>

int main()
{
    int x, y;
    int dx[3] = {-1, 0, 1};
    
    while (std::cin >> x >> y) {

        if (x == 0 && y == 0) break;

        int field[20][20] = {{0}}, dp[20][20] = {{0}};
        
        for (int i = 0; i < 20; ++i) {
            for (int j = 0; j < 20; ++j) {
                field[i][j] = 1;
            }
        }
        
        for (int i = 1; i <= y; ++i) {
            for (int j = 1; j <= x; ++j) {
                std::cin >> field[i][j];
            }
        }

        for (int i = 1; i <= x; ++i) {
            if (field[1][i] == 0) dp[1][i] = 1;
        }
        
        //calc
        int ans = 0;

        for (int i = 1; i <= y; ++i) {
            for (int j = 1; j <= x; ++j) {
                
                switch (field[i][j]) {
                    case 0:
                        for (int k = 0; k < 3; ++k) {
                            int px = j + dx[k], py = i + 1;
                            
                            if ((field[py][px] == 2 && k == 1) || field[py][px] == 0) {
                                dp[py][px] += dp[i][j];
                            }
                        }
                        break;
                    case 2:
                        //y-1
                        if (i == y -1) ans += dp[i][j];
                        if (dp[i + 2][j] != 1) dp[i + 2][j] += dp[i][j];
                        break;
                    default:
                        break;
                }
            }
        }

        for (int i = 1; i <= x; ++i) {
            ans += dp[y][i];
        }

        std::cout << ans << std::endl;
    }

    return 0;
}