#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;
int X,Y,imap[20][20];
const int dx[3] = {-1,0,1};
const int dy[3] = {1,1,1};
int sam,dp[20][20];

int solve(){
  
  int ans = 0;
  for(int i=0;i<=Y;i++)for(int j=0;j<=X;j++)dp[i][j] = (i==0 && imap[i][j] != 1)?1:0; 

  for(int i=0;i<Y-1;i++){
    for(int j=0;j<X;j++){
      if(dp[i][j] == 0 || imap[i][j] == 1)continue;
      if(imap[i][j] == 0){
	for(int k=0;k<3;k++){
	  int nx = j+dx[k],ny = i+dy[k];
	  if(0<= nx && nx<X && 0<= ny && ny < Y && imap[ny][nx] != 1){
	      if((k == 0 || k == 2) && imap[ny][nx] == 2)continue;
	      dp[ny][nx]+=dp[i][j];
	  }
	}
      }
      else if(imap[i][j] == 2){
	if(i+2 < Y && imap[i+2][j] != 1){
	  dp[i+2][j]+=dp[i][j];
	}
	else if(i+2 >= Y){
	  //if(imap[Y-1][j] != 1)
	    dp[Y-1][j]+=dp[i][j];
	}
      }
    }
  }
  /*
  cout << endl;
    for(int i=0;i<Y;i++){
      for(int j=0;j<X;j++)cout << dp[i][j] << " ";
	cout << endl;
    }
  */
    for(int i=0;i<X;i++)ans += dp[Y-1][i];
    return ans;
}



bool Init(){
  cin >> X >> Y;
  if(X+Y == 0)return false;
  for(int i=0;i<Y;i++){
    for(int j=0;j<X;j++){
      cin >> imap[i][j];
    }
  }
  sam = 0;
  return true;
}



int main(){
  while(true){
    if(!Init())break;
    cout << solve() << endl;
  }
  return 0;
}