#include <iostream>
#define N 15
using namespace std;
int data[N][N];
void func(int,int);
int Cnt(int,int);
int X,Y,cnt,memo[N][N];
int main(){
  while(1){
    cin >> X >> Y;
    if(X==0&&Y==0) break;
    for(int i=0;i<Y;i++)
      for(int j=0;j<X;j++)
	cin >> data[i][j];
    cnt=0;
    for(int i=0;i<Y;i++)
      for(int j=0;j<X;j++)
	memo[i][j]=-1;
    for(int i=0;i<X;i++){
      if(data[0][i]==0) func(0,i);
    }
    cout << cnt << endl;
  }
  return 0;
}
void func(int y,int x){
  if(y>=Y-1){
    cnt++;
    memo[Y-1][x]=1;
    return;
  }else memo[Y-1][x]=0;
  if(y+1<Y&&x+1<X&&data[y+1][x+1]==0) func(y+1,x+1);
  if(y+1<Y&&x-1>=0&&data[y+1][x-1]==0) func(y+1,x-1);
  if(y+1<Y&&data[y+1][x]==2){
    int r=Cnt(y,x);
    if(r!=-1){
      if(memo[y+1][x]!=-1) memo[y][x]+=memo[y+1][x];
      func(r,x);
      if(memo[y+1][x]!=-1) memo[y][x]+=memo[y+1][x];
    }
    else return ;
  }
  if(y+1<Y&&data[y+1][x]==0) func(y+1,x);

}
int Cnt(int y,int x){
  y+=3;
  while(1){
    if(y>=Y-1){
      if(y>Y-1) cnt++;
      else if(y==Y-1&&data[y][x]!=1) cnt++;
      break;
    }
    if(data[y][x]==1) break;
    if(data[y][x]==2) y+=2;
    if(data[y][x]==0) return y;
  }
  return -1;
}