### subroutines

def count_rt(x0, y0)
  return 1 if y0 >= $y
  return $rtcache[y0][x0] if ! $rtcache[y0][x0].nil?

  count = 0
  y1 = y0 + 1

  if $flds[y0][x0] == 0
    count += count_rt(x0 - 1, y1) if x0 > 0 && $flds[y1][x0 - 1] == 0
    count += count_rt(x0, y1)
    count += count_rt(x0 + 1, y1) if x0 < $x - 1 && $flds[y1][x0 + 1] == 0
  else
    count += count_rt(x0, y0 + 2)
  end

  $rtcache[y0][x0] = count
end

### main

while true
  $x, $y = gets.strip.split(' ').map{|s| s.to_i}
  break if $x == 0 && $y == 0

  $flds = []
  $y.times.each do
    hl = gets.strip.split(' ').map{|s| s.to_i}
    $flds << hl
  end

  $rtcache = $y.times.map{[nil] * $x}
  $rtcache << [1] * $x

  for y0 in (0...$y)
    for x0 in (0...$x)
      if $flds[y0][x0] == 1
        $rtcache[y0][x0] = 0
      elsif y0 == $y - 1
        $rtcache[y0][x0] = 1
      end
    end
  end

  count = 0
  for x0 in (0...$x)
    count += count_rt(x0, 0)
  end
  puts count
end