#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int x,y;
int map[15][15];
int dp[15][15];

int solve(int i,int j,bool naname){
  //cout<<"a"<<i<<"\t"<<j<<endl;
  if(j < 0 ||j >= x) return 0;
  if(i >= y) return 1;
  if(naname)
    if(map[i][j] == 2)
      return 0;
  if(dp[i][j] >= 0) return dp[i][j];
 
  int ret;

  //cout<<i<<"\t"<<j<<endl;
  switch(map[i][j]){
  case 0:
    ret = solve(i+1,j-1,true) + solve(i+1,j,false)+solve(i+1,j+1,true);
    break;
  case 2:
    ret = solve(i+2,j,false);
    break;
  }

  return dp[i][j] = ret;
}


int main(){
  while(cin>>x>>y){
    if(x == 0 && y==0)
      return 0;
    memset(dp,-1,sizeof(dp));
    for(int i = 0;i<y;i++){
      for(int j = 0;j<x;j++){
	cin>>map[i][j];
	if(map[i][j] == 1)
	  dp[i][j] = 0;
      }
    }
    int ans = 0;
    for(int j = 0;j<x;j++){
      if(map[y-1][j] != 1)
	dp[y-1][j] = 1;
    }
    for(int j = 0;j<x;j++){
      ans += solve(0,j,false);
      // cout<<"ans:"<<ans<<endl;
    }
    cout<<ans<<endl;
    
  }

  return 0;
}