$time_i = 0
$time_e = 0
class Maximum
  def initialize(arr = [])
    @arr = arr
    monky
  end
  def monky
    def @arr.[](i)
      super(i - 1)
    end
    def @arr.[]=(i, value)
      super(i - 1, value)
    end
  end
  def buildHeap(root = 1)
    left, right = root * 2, root * 2 + 1
    if @arr[right]
      buildHeap(left); buildHeap(right)
      max = [[@arr[left], left], [@arr[right], right]].max
      if max[0] > @arr[root]
        @arr[root], @arr[max[1]] = @arr[max[1]], @arr[root]
        rebuildHeap(max[1])
      end
    elsif @arr[left]
      buildHeap(left)
      if @arr[left] > @arr[root]
        @arr[root], @arr[left] = @arr[left], @arr[root]
        rebuildHeap(left)
      end                                                       
    end
  end
  def rebuildHeap(root = 1)
    left, right = root * 2, root * 2 + 1
    if @arr[right]
      max = [[@arr[left], left], [@arr[right], right]].max
      if max[0] > @arr[root]
        @arr[root], @arr[max[1]] = @arr[max[1]], @arr[root]
        rebuildHeap(max[1])
      end
    elsif @arr[left]
      if @arr[left] > @arr[root]
        @arr[root], @arr[left] = @arr[left], @arr[root]
        rebuildHeap(left)
      end
    end      
  end
  def insert(key)
    #start = Time.now
    @arr.push(key.to_i)
    i = @arr.size
    while i / 2 >= 1 and @arr[i / 2] < key.to_i
      @arr[i], @arr[i / 2] = @arr[i / 2], @arr[i]
      i /= 2
    end
    #$time_i += Time.now - start
  end
  def extract
    #start = Time.now
    puts @arr[1]
    @arr[1] = @arr.pop
    rebuildHeap
    #$time_e = Time.now - start
  end
  def to_s
    @arr.join(" ")
  end
end
def main(input = STDIN)
  heap = Maximum.new
  while (order = input.gets.chomp) != "end"
    heap.send(*order.split(" "))
  end
  #p [$time_i, $time_e]
end
#main(f = File.open('input2.txt'))
#f.close
main