// AOJ 0203
#include <iostream>
#include <cstring>

using namespace std;
 
int main(void)
{
    int w, h;
    while (cin >> w >> h, w){
        int field[32][32] = {};
        for (int y = 1; y <= h; y++){
            for (int x = 1; x <= w; x++){
                cin >> field[y][x];
            }
        }
        int dp[32][32];
        memset(dp, 0, sizeof(dp));

        for (int x = 1; x <= w; x++){
            if (field[1][x] == 0){
                dp[1][x] = 1;
            }
        }
        for (int y = 1; y <= h; y++){
            for (int x = 1; x <= w; x++){
                if (field[y][x] == 1){
                    continue;
                }
                if (field[y][x] == 2){
                    dp[y + 2][x] += dp[y][x];
                    continue;
                }
                if (field[y + 1][x - 1] == 0){
                    dp[y + 1][x - 1] += dp[y][x];
                }
                if (field[y + 1][x] != 1){
                    dp[y + 1][x] += dp[y][x];
                }
                if (field[y + 1][x + 1] == 0){
                    dp[y + 1][x + 1] += dp[y][x];
                }
            }
        }
 
        int ret = 0;
        for (int y = h - 1; y <= h; y++){
            for (int x = 1; x <= w; x++){
                if (y == h - 1){
                    if (field[y][x] == 2) ret += dp[y][x];
                    continue;
                }
                else {
                    ret += dp[y][x];
                }
            }
        }
        cout << ret << endl;
    }
 
    return 0;
}