class Heep
  def initialize
    @node = []
  end
  def insert(num) #upheap
    i = @node.size
    @node[i] = num
    while i > 0 && @node[i/2] < @node[i]
      @node[i], @node[i/2] = @node[i/2], @node[i]
      i /= 2
    end
  end
  def extract #downheap
    ret = @node[0]
    @node[0] = @node.pop()
    maxHeapify(@node, 0)
    return ret
  end
  def maxHeapify(a, i)
    h = a.size
    l = 2 * i + 1
    r = 2 * i + 2
    largest = i
    largest = l if l < h && a[l] > a[i]
    largest = r if r < h && a[r] > a[largest]

    if largest != i then
      a[i], a[largest] = a[largest], a[i]
      maxHeapify(a, largest)
    end
  end
end

heep = Heep.new()
loop do
  cmd, num = gets.split
  case cmd;
  when "insert";
    heep.insert(num.to_i)
  when "extract";
    puts heep.extract
  when "end";
    break
  end
end