#include <bits/stdc++.h>

using namespace std;

int field[20][20];
int dp[20][20];

int n, m;

bool isIn(int x, int y){
    return 0 <= x && x < n && 0 <= y && y < m;
}

int main(){
    while(cin >> n >> m, n+m){
        for(int i=0; i < n; i++) for(int j=0; j< m; j++){cin >> field[i][j];}
        for(int i=0; i< 20; i++) for(int j=0; j< 20; j++) dp[i][j] = 0;
        for(int i=0; i < m; i++) dp[0][i] = 1;
        for(int i=0; i < n-1; i++){
            for(int j=0; j < m; j++){
                if(field[i][j] == 0){
                    for(int k=-1; k <= 1; k++){
                        if(isIn(i+1, j+k) && !(k != 0 && field[i+1][j+k] == 2)){
                            dp[i+1][j+k] += dp[i][j];
                        }
                    }
                }
                else if(field[i][j] == 2) dp[i+2][j] += dp[i][j];
            }
        }
        for(int i=0; i< m; i++) if(field[n-1][i] != 1)dp[n][i] += dp[n-1][i];
        long long count = 0;
        for(int i=0; i< m; i++) count += dp[n][i];
        cout << count << endl;
    }
}