class Heep
  def initialize
    @node = []
  end
  def insert(num) #upheap
    @node.push(num)
    i = @node.size - 1
    loop do
      p = (i + 1) / 2 - 1
      break if p < 0
      break if @node[p] > @node[i]
      @node[p], @node[i] = @node[i], @node[p]
      i = p
    end
  end
  def extract #downheap
    ret = @node.shift
    @node.unshift(@node.pop())
    p = 0
    loop do
      i = 2 * p + 1
      break unless i < @node.size
      if i == @node.size-1 || @node[i] > @node[i+1] then
        break unless @node[p] < @node[i]
        @node[p], @node[i] = @node[i], @node[p]
        p = i
      else
        break unless @node[p] < @node[i+1]
        @node[p], @node[i+1] = @node[i+1], @node[p]
        p = i+1
      end
    end
    return ret
  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