public static void main(String[] args) {
        int n = 0;
        Scanner in = new Scanner(new InputStreamReader(System.in));
        try {
            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 {
                    System.out.println(heap.extractMax());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }