MAX = 2000000

def max_heapify(a, i, h)
  left = i * 2
  right = left + 1
  largest = (left <= h && a[left] > a[i]) ? left : i
  largest = right if right <= h && a[right] > a[largest]
  if largest != i
    a[i], a[largest] = a[largest], a[i]
    max_heapify(a, largest, h)
  end
end

class Que
  def initialize
    @a = Array.new(MAX)
    @size = 0
  end

  def insert(k)
    @size += 1
    @a[@size] = k
    up(@size)
  end

  def up(i)
    while i > 1 && @a[i / 2] < @a[i]
      @a[i / 2], @a[i] = @a[i], @a[i / 2]
      i /= 2
    end
  end

  def extract()
    v = @a[1]
    @a[1] = @a[@size]
    @size -= 1
    max_heapify(@a, 1, @size)
    return v
  end
end

que = Que.new
while true
  command, k = gets.split
  if command == 'insert'
    que.insert k.to_i
  elsif command == 'extract'
    puts que.extract
  else
    break
  end
end

