#include <stdio.h>
#include <stdlib.h>
#define SIZE 2000000

int max(int A[], int h, int t) {
    if (h == t) return h;
    int l = max(A, h, (h + t) / 2), r = max(A, (h + t) / 2 + 1, t);
    if (A[l] > A[r]) return l;
    else return r;
}

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

    return 0;
}
