cmds = []
while true do
    cmd = gets.chomp.split(' ')
    break if cmd[0] == "end"
    cmd[1] = cmd[1].to_i unless cmd[1].nil?
    cmds.push(cmd)
end

INF = 20005
heap = [nil]
heapSize = 0

def heapIncreaseKey(heap, i, key)
    if key < heap[i] then
        puts "ERROR : The new key is less than the current key."
        exit
    end
    heap[i] = key
    while i > 1 && heap[i / 2] < heap[i]
        tmp = heap[i]
        heap[i] = heap[i / 2]
        heap[i / 2] = tmp
        i = i / 2
    end
end

def heapInsert(heap, key)
    heap[heap.size] = INF * (-1)
    heapIncreaseKey(heap, heap.size - 1, key)
end

def maxHeapify(heap, i)
    l = i * 2
    r = i * 2 + 1
    if l <= heap.size - 1 && heap[l] > heap[i] then
        largest = l
    else
        largest = i
    end
    if r <= heap.size - 1 && heap[r] > heap[largest] then
        largest = r
    end
    
    if largest != i then
        tmp = heap[i]
        heap[i] = heap[largest]
        heap[largest] = tmp
        maxHeapify(heap, largest)
    end
end

def heapExtractMax(heap)
    puts "ERROR : Heap Underflow" if heap.size - 1 < 1
    max = heap[1]
    heap[1] = heap[heap.size - 1]
    maxHeapify(heap, 1)
    heap.pop
    return max
end

cmds.each do |cmd|
    if cmd[0] == "insert" then
        heapInsert(heap, cmd[1])
        # p heap
    else
        puts heapExtractMax(heap)
        # p heap
    end
end

