#include <stdio.h>


// I/O
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
void put_str(char *str) { while(*str) putchar_unlocked(*str++); }
//


// priority queue
typedef struct MaxHeap {
    int A[2000001];
    size_t len;
} MaxHeap;
void maxheap_init(MaxHeap *H) { H->len = 0; }
void maxheap(MaxHeap *H, const int i) {
    const size_t N = H->len;
    int l = i * 2;
    int r = i * 2 + 1;
    int max = i;
    if(l <= N && H->A[l] > H->A[max]) max = l;
    if(r <= N && H->A[r] > H->A[max]) max = r;
    if(max != i) {
        int tmp = H->A[i];
        H->A[i] = H->A[max];
        H->A[max] = tmp;
        maxheap(H, max);
    }
}
void maxheap_insert(MaxHeap *H, int key) {
    size_t i = ++H->len;
    H->A[i] = key;
    while(i > 1 && H->A[i / 2] < H->A[i]) {
        int tmp = H->A[i/2];
        H->A[i/2] = H->A[i];
        H->A[i] = tmp;
        i /= 2;
    }
}
int maxheap_pop(MaxHeap *H) {
    if(!H->len) return -1;
    int max = H->A[1];
    H->A[1] = H->A[H->len--];
    maxheap(H, 1);
    return max;
}
//


int main(int argc, char **argv) {
    int key;
    char c[8];
    MaxHeap H;
    maxheap_init(&H);
    while(1) {
        get_str(c);
        if(*c == 'e') {
            if(c[1] == 'n') break;
            put_uint(maxheap_pop(&H));
            putchar_unlocked('\n');
        } else {
            key = get_uint();
            maxheap_insert(&H, key);
        }
    }
    return 0;
}

