#include <stdio.h>
#include <stdlib.h>

#define NIL -1

int parent(int i){
    return 1 / 2;
}

int left(int i){
    return 2 * i;
}

int right(int i){
    return 2 * i + 1;
}

void heapIncreaseKey(int *h, int i, int key){

    int tmp;

    if (key < h[i]) return;
    
    h[i] = key;

    while(i > 1 && h[parent(i)] < h[i]){
        tmp = h[i];
        h[i] = h[parent(i)];
        h[parent(i)] = tmp;
        i = parent(i);
    }
}

void maxHeapInsert(int *h, int key, int n){
    n = n + 1;
    h[n] = NIL;
    heapIncreaseKey(h, n, key);
}

void maxHeapify(int* h, int i, int n){
    
    int l, r, x, largest;
    
    l = left(i);
    r = right(i);
    
    if(l <= n && h[l] > h[i]) largest = l;
    else largest = i;
    
    if(r <= n && h[r] > h[largest]) largest = r;
    
    if(largest != i){
        x = h[i];
        h[i] = h[largest];
        h[largest] = x;
        maxHeapify(h, largest, n);
    }
}

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

int heapExtractMax(int *h, int n){

    int max;
    
    if(n < 1) return 0;
    
    max = h[1];
    h[1] = h[n];
    n = n - 1;
    
    maxHeapify(h, 1, n);
    
    return max;

}


int main(){
    
    int n, x;
    int* h;
    char com[10];
    
    h = malloc(sizeof(int) * n);
    
    while(1){
        scanf("%s", com);
        
        if(com[0] == 'i'){
            scanf("%d", &x);
            maxHeapInsert(h, x, n);
        }
        else if(com[0] == 'e')
            printf("%d\n", heapExtractMax(h, n));
        else if(com[1] == 'n') break;
    }
    
    return 0;
    
}