#include <cstdio>
#include <cstring>
int w,h;
int f[22][22];
int dp[22][22];
int dx[] = {-1,0,1};
int solve(int x,int y){
  //printf("(%d,%d) = %d\n",x,y,f[x][y]);
  if(f[x][y] == 1) return 0;
  if(y >= h){
    //puts("OK ... 1");
    return 1;
  }
  if(f[x][y] == 1) return 0;
  if(dp[x][y] >= 0){
    //printf("OK ... %d\n",dp[x][y]);
    return dp[x][y];
  }
  if(f[x][y] == 2){
    //puts("Jump");
    return dp[x][y] = solve(x,y + 2);
  }

  int ret = 0;
  for(int i = 0; i < 3; i++){
    int nx = x + dx[i];
    if(!f[nx][y+1] || (!dx[i] && f[nx][y+1] == 2)){
      ret += solve(nx,y+1);
    }
  }
  return dp[x][y] = ret;
}
int main(void){
  while(1){
    scanf("%d%d",&w,&h); if(!w) break;
    memset(f,-1,sizeof(f));
    memset(dp,-1,sizeof(dp));
    for(int i = 1; i <= h; i++){
      for(int j = 1; j <= w; j++){
	scanf("%d",&f[j][i]);
      }
    }
    int ans = 0;
    for(int j = 1; j <= w; j++){
      ans += solve(j,1);
    }
    printf("%d\n",ans);
  }
}