require 'set'
def execute_order(orders)
  set = Set.new
  length = orders.length
  for i in 0..(length-1)
    if orders[i][0] == "insert"
      set.add(orders[i][1].to_i)
    elsif orders[i][0] == "extract"
      max = set.max
      count = set.count(max)
      set.delete(max)
      if count != 1
        (count-1).times do
          set.add(max)
        end
      end
      puts max
    else
      puts "error!"
    end
  end
end

input_orders = []
while true
  input_order = gets.chomp.split
  if input_order == ["end"]
    break
  else
    input_orders.push(input_order)
  end
end

execute_order(input_orders)