#include <stdio.h>
#include <stdlib.h>
 
void max_heapify(int *heap, int i) {
    int heap_size, L, R, largest, tmp;
 
    heap_size = heap[0];
    L = 2*i;
    R = 2*i + 1;
    if (L <= heap_size && heap[L] > heap[i]) {
        largest = L;
    } else {
        largest = i;
    }
    if (R <= heap_size && heap[R] > heap[largest]) {
        largest = R;
    }
    if (largest != i) {
        tmp = heap[i];
        heap[i] = heap[largest];
        heap[largest] = tmp;
        max_heapify(heap, largest);
    }
}
 
int main(void) {
    int *heap, key, index, half, tmp;
    char cmd[20];
 
    heap = malloc(sizeof(int) * 2000001);
    heap[0] = 1;
    while (1) {
        scanf("%s %d ", cmd, &key);
        if (cmd[0] == 'i') {
            heap[0]++;
            index = heap[0];
            heap[index] = key;
 
            half = index / 2;
            while (index > 1 && heap[half] < heap[index]) {
                tmp = heap[index];
                heap[index] = heap[half];
                heap[half] = tmp;
                index /= 2;
                half = index / 2;
            }
        } else if (cmd[1] == 'x') {
            printf("%d\n", heap[1]);
            heap[1] = heap[heap[0]];
            heap[0]--;
            max_heapify(heap, 1);
        } else {
            return 0;
        }
    }
    return 0;
}