/*
 * FileName:     priority_queue_fix
 * CreatedDate:  2020-08-19 22:46:16 +0900
 * LastModified: 2020-08-19 23:10:38 +0900
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define m 2000000

void heapify(int *Q, int index){
    if(index/2==0){
        return;
    }
    if(Q[index]>Q[index/2]){
        int tmp = Q[index];
        Q[index] = Q[index/2];
        Q[index/2] = tmp;
        heapify(Q, index/2);
    }
}
void reheapify(int *Q, int index, int H){
    if(2*index>H){
        return;
    }
    int key=index;
    if(2*index<=H && Q[index]<Q[2*index]){
        key=2*index;
    }
    if(2*index+1<=H && Q[key]<Q[2*index+1]){
        key=2*index+1;
    }
    if(key!=index){
        int tmp = Q[index];
        Q[index] = Q[key];
        Q[key] = tmp;
        reheapify(Q, key, H);
    }

}
int extract(int *Q, int index){
    int ans =  Q[1];
    Q[1] = Q[index-1];
    reheapify(Q, 1, index-1);
    return ans;
}
void print(int *Q, int H){
    for(int i=1; i<H; i++){
        printf("%d ", Q[i]);
    }
    printf("\n");
}
int main(void){
    int *S = malloc(m*sizeof(int));
    memset(S, -1, sizeof(S));
    int index = 1;
    while(1){
        char command[10];scanf("%s", command);
        if(command[0]=='i'){
            int k;scanf("%d", &k);
            S[index] = k;
            heapify(S, index++);
//            print(S, index);
        }
        else if(command[1]=='x'){
            printf("%d\n", extract(S, index--));
//            print(S, index);
        }
        else{
            break;
        }
    }
    return 0;
}

