#include<stdio.h>
#include<string.h>
#define N 2000000
#define INFTY 5000000

void maxHeap(int);
int heapExtractMax(void);
void heapIncreaseKey(int,int);
void insert(int);

int H = 0;
int order[N+1];

int main(){
    char str[8];
    int key;

    while(1){
        scanf("%s",str);
        if(strcmp(str,"end") == 0){
            break;
        }
        if(strcmp(str,"insert") == 0){
            scanf("%d",&key);
            insert(key);
        }
        else{
            printf("%d\n",heapExtractMax());
        }
    }

    return 0;
}

void maxHeap(int i){
    int l,r,largest,tmp;

    l = 2*i;
    r = 2*i+1;

    if(l <= H && order[l] > order[i]){
        largest = l;
    }
    else{
        largest = i;
    }
    if(r <= H && order[r] > order[largest]){
        largest = r;
    }

    if(largest != i){
        tmp = order[i];
        order[i] = order[largest];
        order[largest] = tmp;
        maxHeap(largest);
    }
}

int heapExtractMax(){
    int max;

    if(H<1) return -INFTY;
    max = order[1];
    order[1] = order[H];
    H--;
    maxHeap(1);
    return max;
}

void heapIncreaseKey(int i,int key){
    int tmp;

    if(key < order[i]){
        return;
    }
    order[i] = key;
    while(i > 1 && order[i/2] < order[i]){
        tmp = order[i];
        order[i] = order[i/2];
        order[i/2] = tmp;
        i = i/2;
    }
}

void insert(int key){
    H++;
    order[H] = -INFTY;
    heapIncreaseKey(H,key);
}
