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

#define N 2000002
#define NN 10

int num = 0;

void Defma(int *t, int i){
    int left, right;
    int  large, c;

    if( i * 2 + 1 < num + 1) right = i * 2 + 1;
    else right = i;
    if( i * 2 < num + 1) 
        left = i * 2;
    else left = i;

    if(left <= num && t[left] > t[i])
        large = left;
    else large = i;

    if(right <= num && t[right] > t[large])
        large = right;

    if(large != i){
        c = t[i];
        t[i] = t[large];
        t[large] = c;

        Defma(t, large);
    }
}

void Defin(int *arrayt, int z){
    int i,c;

    num++;
    i = num;
    arrayt[num] = z;

    while(i > 1 && arrayt[i/2] < arrayt[i]){

        c = arrayt[i];

        arrayt[i] = arrayt[i/2];

        arrayt[i/2] = c;
        i /= 2;
    }
}

void Defex(int *arrayt){

    printf("%d\n", arrayt[1]);

    if(num > 1) arrayt[1] = arrayt[num];

    num--;

    if(num > 1) Defma(arrayt, 1);
}

int main(){
    int i;
    int Arrayt[N];
    char Array[NN];

    while(1){
        scanf("%s", Array);

        if(Array[2] == 'd') break;
        else if(Array[0] == 'i'){
            scanf("%d", &Arrayt[0]);
            Defin(Arrayt, Arrayt[0]);
        }
        else Defex(Arrayt);
    }

    return 0; 
}


