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