#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int dp[15][16];
int fld[15][15];
int main(){
      int x,y;
      while(cin>>x>>y&&(x||y)){
            REP(i,y)REP(j,x)cin>>fld[j][i];
            memset(dp,0,sizeof(dp));
            REP(i,x)if(fld[i][0]==0)dp[i][0]=1;
            REP(i,y-1){
                  REP(j,x){
                        if(fld[j][i]==0){
                              for(int k=-1;k<=1;k++){
                                    if(j+k<0||j+k>=x)continue;
                                    //cout<<j+k<<" "<<i+1<<" "<<j<<" "<<i<<endl;
                                    if(fld[j+k][i+1]==0){
                                          //cout<<j+k<<" "<<i+1<<" "<<j<<" "<<i<<endl;
                                          dp[j+k][i+1]+=dp[j][i];
                                    }
                                    else if(fld[j+k][i+1]==2&&k==0)dp[j+k][i+1]+=dp[j][i];
                              }
                        }else if(fld[j][i]==2){
                              int to=min(y,i+2);
                              if(to==y||fld[j][to]!=1)dp[j][to]+=dp[j][i];
                        }
                  }
                  //REP(k,x)cout<<dp[k][i+1]<<" ";cout<<endl;
            }
            //REP(i,y+1)REP(j,x)printf("%2d%c",dp[j][i],j==x-1?'\n':' ');
            int ans=0;
            REP(i,2)REP(j,x)ans+=dp[j][y-i];
            cout<<ans<<endl;
      }
}