class MaximumHeap
  attr_accessor :tree

  def initialize
    @tree = [nil]
    @heapsize = 0
  end

  def insert(key)
    @heapsize += 1
    @tree[@heapsize] = -Float::INFINITY
    heap_increase_key(@heapsize, key)
  end

  def heap_increase_key(i, key)
    raise Exception.new if key < @tree[i]
    @tree[i] = key
    parent = i / 2
    while parent > 0 && i > 0 && @tree[parent] < @tree[i]
      @tree[parent], @tree[i] = @tree[i], @tree[parent]
      i = parent
    end
  end

  def heap_extract_max
    raise Exception.new if @heapsize < 1
    max = @tree[1]
    @tree[1] = @tree[@heapsize]
    @heapsize -= 1
    max_heapify(1)
    return max
  end

  def max_heapify(i)
    l = i * 2
    r = i * 2 + 1
    if l <= @heapsize - 1 && @tree[l] > @tree[i]
      largest = l
    else
      largest = i
    end
    if r <= @heapsize && @tree[r] > @tree[largest]
      largest = r
    end

    if largest != i
      @tree[i], @tree[largest] = @tree[largest], @tree[i]
      max_heapify(largest)
    end
  end
end

mh = MaximumHeap.new
while ( line = gets.strip ) != "end"
  cmd, key = line.split
  case cmd
  when "insert"
    mh.insert(key.to_i)
  when "extract"
    puts mh.heap_extract_max
  end
end