#include <iostream>
#include <algorithm>

using namespace std;

int dy[] = { 1, 1, 1};
int dx[] = { -1, 0, 1 };

int main() {
    while (1) {
        int dp[17][15] = { 0 };
        int field[15][15] = { 0 };
        int h, w;

        cin >> w >> h;
        if (w == 0) {
            break;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> field[i][j];
            }
        }
        
        for (int j = 0; j < w; j++) {
            if (field[0][j] != 1) {
                dp[0][j] = 1;
            }
        }
        
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (dp[i][j] > 0) {
                    if (field[i][j] == 2) {
                        if (field[i + 2][j] != 1) {
                            dp[i + 2][j] += dp[i][j];
                        }
                        continue;
                    }
                    if (i == h - 1) {
                        dp[i + 1][j] = dp[i][j];
                        continue;
                    }
                    for (int k = 0; k < 3; k++) {
                        int nx = j + dx[k];
                        int ny = i + dy[k];
                        if (nx < 0 || nx >= w) {
                            continue;
                        }
                        if (field[ny][nx] == 0 || (field[ny][nx] == 2 && k == 1)) {
                            dp[ny][nx] += dp[i][j];
                        }
                    }
                }
            }
        }
        
        int ans = 0;
        for (int i = h; i <= h + 1; i++) {
            for (int j = 0; j < w; j++) {
                ans += dp[h][j];
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}