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

int PQueue[2000001];
int max_index = -1;

void insert(int num){
    PQueue[num]++;
    if (num > max_index) {
        max_index = num;
    }
}

void extract(){
    
    printf("%d\n", max_index);
    PQueue[max_index]--;
    
    if (PQueue[max_index] == 0) {
        while (!PQueue[max_index]){
            max_index--;
        }
    }
}


int main( ){
    
    int operand;
    char operator[20];
    
    while (1) {
        
        scanf("%s", operator);
        
        if (strcmp(operator, "insert") == 0) {
            scanf("%d", &operand);
            insert(operand);
        }
        else if(strcmp(operator, "extract") == 0){
            extract();
        }
        else{
            break;
        }
    }

    
    return 0;
}