#include<stdio.h>
#define N 2000000
#define M 8
int tum[N];
int size;

void sum(int tum[], int i) {
    int a = 2 * i + 1;
    int b = 2 * i + 2;
    int xu;

    if (a <= size && tum[a] > tum[i]) {
        xu = a;
    } else {
        xu = i;
    }
    if (b <= size && tum[b] > tum[xu]) {
        xu = b;
    }

    if (xu != i) {
        int tmp = tum[i];
        tum[i] = tum[xu];
        tum[xu] = tmp;
        sum(tum, xu);
    }
}

void fan(int k){
    int bro = size;
    int gra = (bro - 1) / 2;

    tum[size] = k;

    while(1){
        if(tum[gra] > tum[bro] || bro == 0)
            break;
        int tmp = tum[bro];
        tum[bro] = tum[gra];
        tum[gra] = tmp;

        bro = gra;
        gra = (bro - 1) / 2;
    }

    size++;
}

int zin(){
    int ret = tum[0];
    tum[0] = tum[size-1];
    size--;
    sum(tum, 0);
    return ret;
}

int main(){
    char gum[M];
    int k;

    while(1) {
        scanf("%s",gum);
        if(gum[0] == 'i'){
            scanf("%d", &k);
            fan(k);
        }else if(gum[1] == 'x'){
            printf("%d\n",zin());
        }else{
            return 0;
        }
    }
}

