def extract_max
  max = $array[0]
  max_index = 0
  $array.each_with_index do |value, index|
    if (max <=> value) == -1
      max = value
      max_index = index
    end
  end
  $array.delete_at max_index
  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

