class PriorityQueue
  def initialize
    @array = []
    @size = 0
  end
  
  def push(a)
    @array[@size] = a
    heapify_up(@size)
    @size += 1
  end
  
  def pop()
    raise unless @size > 0
    ans = @array[0]
    @size -= 1
    @array[0] = @array[@size]
    heapify_down(0)
    ans
  end

  def swap(p,q)
    @array[p], @array[q] = @array[q], @array[p]
  end

  def equal_or_better(p,q)
    (@array[p] <=> @array[q]) <= 0
  end

  def heapify_up(n)
    while n > 0
      parent = (n - 1) / 2
      break if equal_or_better(parent, n)
      swap(parent,n)
      n = parent
    end
  end

  def heapify_down(n)
    while true
      l, r = n * 2 + 1, n * 2 + 2
      break if @size <= l
      child = l
      child = r if r < @size && equal_or_better(r, l)
      break if equal_or_better(n, child)
      swap(child, n)
      n = child
    end
  end
end

Q = PriorityQueue.new
count = 0
while true do
  s, n = gets.split
  break if s == "end"

  if s == "insert"
    Q.push([-n.to_i, count])
    count += 1
  else
    p -(Q.pop()[0])
  end
end