#include <iostream>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main(){
    int w,h;
    while(cin>>w>>h, w||h){
        int G[100][100];
        int dp[100][100]={};
        rep(i,h)rep(j,w) cin>> G[i][j];

        rep(i,w) dp[0][i] = G[0][i]==0;

        rep(i,h-1) rep(j,w){
            if( G[i][j]==1){
                dp[i][j]=0;
            } else if(G[i][j]==2 && G[i+2][j]!=1){
                dp[i+2][j]+=dp[i][j];
            } else {
                if(G[i+1][j]==2) dp[i+1][j]+=dp[i][j];
                loop(k,-1,2){
                    if(0<=j+k && j+k<w && G[i+1][j+k]==0){
                        dp[i+1][j+k]+=dp[i][j];
                    }
                }
            }
        }

        ull res=0;
        loop(i,h-1,h+1)rep(j,w){
            if(G[i][j]!=1)res+=dp[i][j];
        }

        cout<<res<<endl;
    }
}