#include <bits/stdc++.h>
using namespace std;

int main()
{
    int W, H;


    while ( cin >> W >> H, W || H ) {
        int dp[22][22] = {};
        int mas[22][22] = {};

        for ( int i = 0; i < H; i++ ) {
            for ( int j = 0; j < W; j++ ) {
                cin >> mas[i][j];
            }
        }

        for ( int i = 0; i < W; i++ ) {
            if ( mas[0][i] == 0 ) {
                dp[0][i] = 1;
            }
        }

        for ( int i = 0; i < H - 1; i++ ) {
            for ( int j = 0; j < W; j++ ) {
                if ( mas[i][j] == 2 ) {
                    if ( mas[i + 2][j] != 1 ) {
                        dp[i + 2][j] += dp[i][j];
                    }
                } else {
                    for ( int k = -1; k <= 1; k++ ) {
                        if ( 0 <= j + k && j + k < W ) {
                            if ( mas[i + 1][j + k] == 0 ) {
                                dp[i + 1][j + k] += dp[i][j];
                            } else if ( k == 0 && mas[i + 1][j] == 2 ) {
                                dp[i + 1][j] += dp[i][j];
                            }
                        }
                    }
                }
            }
        }
        int sum = 0;
        for ( int i = 0; i < W; i++ ) {
            sum += dp[H - 1][i] + dp[H][i];
        }

        cout << sum << endl;
    }
    return ( 0 );
}

