#include<iostream>
#include<algorithm>
#include<cstring>
 
using namespace std;
 
const int MAX = 17;
short in[MAX][MAX];
int  X,Y,data[MAX][MAX],ans;
int dx[4] = {-1,0,1};
 
 
void init(){
  memset(data,0,sizeof(data));
  ans = 0;
}
 
 
void solve(){
  for(int i = 1; i <= Y; i++)
    for(int j = 1; j <= X; j++){
      for(int k = 0; k < 3; k++)
	if(in[i][j] == 2){
	  if(in[i+2][j] != 1) data[i+2][j] += data[i][j];
	  break;
	}else if(in[i][j] == 0){
	  int nex = j+dx[k];
	  if(nex < 1 || nex > X) continue;

	  if(in[i+1][nex] == 2 && dx[k] == 0) data[i+1][nex] += data[i][j];
	  if(in[i+1][nex] == 0) data[i+1][nex] += data[i][j];

	}
    }
  
  for(int j = 1; j <= X; j++){
    if(Y-1 > 0 && in[Y-1][j] == 2) ans+=data[Y-1][j];
    ans+=data[Y][j];
  }
  cout << ans << endl;
}
 
void print(){
  for(int i = 1; i <= Y; i++){
    for(int j = 1; j <= X; j++)
      cout << data[i][j]<< " ";
    cout << endl;
  }
}
int main(){
  while(cin >> X >> Y && X+Y){
    init();
    for(int i = 1; i <= Y; i++)
      for(int j = 1; j <= X; j++)
    cin >> in[i][j];
     
    for(int i = 1; i <= X; i++)
      if(in[1][i] == 0) data[1][i] = 1;
 
    solve();
    //print();
  }
  return 0;
}