class Heep
  def initialize
    @node = []
  end
  def insert(num)
    i = @node.size
    @node[i] = num
    down-heap(i)
  end
  def extract
    ret = @node[0]
    @node[0] = @node.pop()
    up-heap(0)
    return ret
  end
  def modify(i, val)
    if @node[i] > val
      @node[i] = val
      down-heap(i)
    else
      @node[i] = val
      up-heap(i)
    end
  end
  def up-heap(i)
    h = @node.size
    largest = i
    l = 2 * i + 1
    largest = l if l < h && @node[l] > @node[largest]
    r = 2 * i + 2
    largest = r if r < h && @node[r] > @node[largest]
    if largest != i then
      @node[i], @node[largest] = @node[largest], @node[i]
      up-heap(largest)
    end
  end
  def down-heap(i)
    p = (i+1)/2-1
    while i > 0 && @node[p] < @node[i]
      @node[i], @node[p] = @node[p], @node[i]
      i = p
      p = (i+1)/2-1
    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