public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        HeapList<Integer> heap = new HeapList<>(n);
        for (int i = 0 ; i < n; i++){
            String cmd = in.next();
            if ("Insert".equals(cmd)){
                heap.insert(in.nextInt());
            } else {
                out.println(heap.extractMax());
            }
        }
    }