#include <stdio.h>
#include <stdlib.h>
#define SIZE 2000000
int h = 1, t = 1;

void maxHeapify(int *A, int i) {
    int l = 2 * i + h - 1 , r = l + 1, max;
    if (l < t && A[l] > A[i + h - 1]) max = l;
    else max = i + h - 1;
    if (r < t && A[r] > A[max]) max = r;

    if (max != i + h - 1) {
        int t = A[i + h - 1];
        A[i + h - 1] = A[max];
        A[max] = t;
        maxHeapify(A, max - h + 1);
    }
}

void buildMaxHeap(int *A) {
    int i;
    for (i = (t - h) / 2; i > 0; i--)
        maxHeapify(A, i);
}

int main(void) {
    int i, A[SIZE];
    char command[10];
    while (scanf("%s", command) != EOF) {
        if (command[2] == 's') {
            int k;
            scanf("%d", &k);
            A[t++] = k;
            buildMaxHeap(A);
        }
        else if (command[2] == 't') {
            buildMaxHeap(A);
            //for (i = h; i < t; i++) printf("%d ", A[i]);
            printf("%d\n", A[h++]);
        }
        else break;
    }

    return 0;
}
