class Pque
  def initialize(max)
    @h = 0
    @a = Array.new(max+1)
    @INF = 1<<30
  end
  
  def max_heapify(i)
    l = 2*i
    r = 2*i+1
    
    if l<=@h && @a[l]>@a[i]
      largest = l
    else
      largest = i
    end
    
    if r<=@h && @a[r] > @a[largest]
      largest = r
    end
    
    if largest != i
      @a[i], @a[largest] = @a[largest], @a[i]
      max_heapify(largest)
    end
  end
  
  def extract
    if @h <1
      return -@INF
    end
    
    maxv = @a[1]
    @a[1] = @a[@h]
    @h-=1
    max_heapify(1)
    return maxv
  end
  
  def increase_key(i, key)
    if key < @a[i]
      return
    end
    
    @a[i] = key
    
    while i>1 && @a[i/2] < @a[i]
      @a[i], @a[i/2] = @a[i/2], @a[i]
      i = i/2
    end
  end
  
  def insert(key)
    @h+=1
    @a[@h] = -@INF
    increase_key(@h, key)
  end
end

q = Pque.new(2000000)

while true
  command = gets.chomp.split
  case command[0]
  when "end"
    break
  when "insert"
    q.insert(command[1].to_i)
  when "extract"
    puts q.extract
  end
end

