$heap = []
def extract_max
  $heap.pop
end

def insert(key)
  $heap << key
  # merge_sort $heap
  $heap.sort!
end

loop do
  input = gets.split ' '
  case input[0]
  when 'insert'
    insert input[1].to_i
  when 'extract'
    puts extract_max
  when 'end'
    break
  end
end

