queue = []

while (line = gets.strip) != "end"
  cmd, key = line.split
  case cmd
  when "insert"
    queue << key.to_i
  when "extract"
    i = queue.index(queue.max)
    puts queue[i]
    queue.delete_at(i)
  end
end