#include<iostream>
using namespace std;
int solve(int x,int y);
int ax,ay;
int mas[20][20];
int memo[20][20];
int main(){
  while(1){
    int ans=0;
    cin>>ax>>ay;
    if(ax==0 && ay==0) break;
    for(int i=1;i<=ay;i++){
      for(int j=1;j<=ax;j++){
	cin>>mas[i][j];
	memo[i][j]=0;
      }
    }
    for(int i=1;i<=ax;i++){
      if(mas[1][i]!=1){
	ans+=solve(i,1);
      }
    }
    cout<<ans<<endl;
  }
}
int solve(int x,int y){
  if(y>=ay){
    return 1;
  }else if(memo[y][x]!=0){
    return memo[y][x];
  }else if(mas[y][x]==2){
    if(mas[y+2][x]!=1){
      return memo[y][x]=solve(x,y+2);
    } 
    else{
      return 0;
    }
  }
  else if(mas[y][x]==1){
    return 0;
  }
  else{
    int anss=0; 
    if(mas[y+1][x]!=1){
      anss+=solve(x,y+1);
    }
    if(x+1<=ax && 0<x+1 && mas[y+1][x+1]==0){
      anss+=solve(x+1,y+1);
    }
    if(0<x-1 && x-1<=ax && mas[y+1][x-1]==0){
      anss+=solve(x-1,y+1);
    }
    return memo[y][x]=anss;
  }
}