def extract_max
  max = $array.max
  $array.delete_at $array.index max
  max
end

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

