class Node
  include Comparable

  def initialize(id, key)
    @id = id
    @key = key
  end

  def <=>(other)
    @key <=> other.key
  end

  DUMMY = Node.new(-1, -2_000_000_001)

  attr_accessor :id, :key
end

def maxHeapify(array, i)
  left = (i*2 < array.size) ? array[i*2] : Node::DUMMY
  right = (i*2+1 < array.size) ? array[i*2+1] : Node::DUMMY
  max = [array[i], left, right].sort_by{|x| x.key}.pop
  max_key = max.key
  if (left.key == max.key) then
    left.key = array[i].key
    array[i].key = max_key
    maxHeapify(array, left.id)
  elsif (right.key == max.key) then
    right.key = array[i].key
    array[i].key = max_key
    maxHeapify(array, right.id)
  end
end

def buildMaxHeap(array)
  ((array.size-1) / 2).downto(1) do |i|
    maxHeapify(array, i)
  end
end

def insert(array, i)
  array << Node.new(array.size, i)
  buildMaxHeap(array)
end

def extract(array)
  if (array.size >= 2) then
    max = array[1].key
    array.delete_at(1)
    buildMaxHeap(array)
    return max
  else
    return nil
  end
end

# main
array = [nil]
while line = gets do
  inputs = line.chomp.split
  if (inputs[0] == 'insert') then
    insert(array, inputs[1].to_i)
  elsif(inputs[0] == 'extract') then
    puts extract(array)
  else
    break
  end
end