#include <stdio.h>
#include <string.h>

static int heap[2000000+1];
static int heap_size = 0;

static void exchange(int A[], int x, int y) {
    int t = A[x];
    A[x] = A[y];
    A[y] = t;

    return;
}

static void sink(int A[], int size, int i) {
    int l = i * 2;
    int r = i * 2 + 1;
    int larger;
    
    if ( l > size ) {           /* no child */
        return;
    }

    if ( r > size ) {           /* left is only one child */
        larger = l;
    } else {
        if ( A[l] > A[r] ) {
            larger = l;
        } else {
            larger = r;
        }
    }

    if ( A[i] < A[larger] ) {
        exchange(A, i, larger);
        sink(A, size, larger);
    }

    return;
}

static void swimUp(int A[], int size, int i) {
    int parent = i / 2;

    if ( parent < 1 ) {
        return;                 /* no parent */
    }

    if ( A[parent] < A[i] ) {
        exchange(A, parent, i);
        swimUp(A, size, parent);
    }

    return;
}

static void insert(int k) {
    heap_size++;
    heap[heap_size] = k;
    swimUp(heap, heap_size, heap_size);

    return;
}

static int extractMax(void) {
    int max = heap[1];

    exchange(heap, 1, heap_size);
    heap_size--;

    sink(heap, heap_size, 1);

    return max;
}
    
int main(int argc, char* argv[]) {
    char buf[20];
    int num;

    while ( scanf("%s %d\n", buf, &num) != EOF ) {
        if        ( strcmp("end", buf) == 0 ) {
            break;
        } else if ( strcmp("insert", buf) == 0 ) {
            insert(num);
        } else if ( strcmp("extract", buf) == 0 ) {
            int max = extractMax();
            printf("%d\n", max);
        }
    }

    return 0;
}
    

