#include <cstdio>
#include <iostream>

#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

int main(){
    int X,Y;
    while(cin >> X >> Y,X+Y){
        int fld[20][20] = {0};
        rep(y,Y){
            rep(x,X){
                cin >> fld[y][x];
            }
        }

        int dp[20][20] = {0};
        rep(x,X){
            if(fld[0][x] == 0)
                dp[0][x] = 1;
        }

        rep(y,Y-1){
            rep(x,X){
                int val = dp[y][x];
                if(fld[y][x] == 0){
                    if(x>0 && fld[y+1][x-1] != 2){
                        dp[y+1][x-1] += val;
                    }
                    if(fld[y+1][x+1] != 2){
                        dp[y+1][x+1] += val;
                    }
                    dp[y+1][x] += val;
                }else if(fld[y][x] == 2){
                    dp[y+2][x] += val;
                }
            }
        }

        int ans = 0;
        rep(i,2){
            rep(x,X){
                if(fld[Y+i-1][x] == 0)
                    ans += dp[Y+i-1][x];
            }
        }
        cout << ans << endl;
    }
    return 0;
}