while true
  x, y = gets.split.map(&:to_i)
  break if x + y == 0
  
  in_course = -> (a, b) { -1 < a && a < x && -1 < b && b < y }
  
  course = Array.new(y) { gets.split.map(&:to_i) } << Array.new(x) { 3 }
  routes = Array.new(y + 1) { Array.new(x) { 0 } }
  direction = [[-1, -1], [-1, 0], [-1, 1]]
  
  course.each_with_index do |row, j|
    row.each_with_index do |grid, i|
      if j == 0
        routes[j][i] = grid == 0 ? 1 : 0
      else
        case grid
        when 0
          direction.each do |dir|
            b_y, b_x = j + dir[0], i + dir[1]
            routes[j][i] += routes[b_y][b_x] if in_course[b_x, b_y] && course[b_y][b_x] == 0
          end
        when 1
        when 2
          routes[j][i] += routes[j - 1][i]
          routes[j + 2][i] += routes[j][i]
        when 3
          routes[j][i] += routes[j - 1][i]
        end
      end
    end
  end
  
  puts routes.last.reduce(:+)
end