#include <stdio.h>

void heapnew(int a[],int l){
    int k;
    if(l<=1){return;}
    if(a[l-1]>a[l/2-1]){
        k=a[l-1];a[l-1]=a[l/2-1];a[l/2-1]=k;
        heapnew(a,l/2);
    }
}

void insert(int a[],int n,int k){
    a[n]=k;n++;
    heapnew(a,n);
}

void heap(int a[],int i,int n){
    int max,k,l;
    if(i*2>n){
        return;
    }
    max = a[i-1];k=i;
    if(max<a[i*2-1]){
        max=a[i*2-1];k=i*2;
    }
    if(i*2+1<=n&&max<a[i*2]){
        max=a[i*2];k=i*2+1;
    }
    if(k!=i){
        l=a[i-1];a[i-1]=a[k-1];a[k-1]=l;
        heap(a,k,n);
    }
}

int main(void){
    int n,x;
    int a[2000000];
    char str[8];
    n=0;
    while(1){
         scanf("%s",str);
        if(str[0]=='e'&&str[1]=='n'){
            break;
        }else if(str[0]=='e'&&str[1]=='x'){
            printf("%d\n",a[0]);
            a[0]=a[n-1];n--;
            heap(a,1,n);
        }else{
            scanf("%d",&x);
            insert(a,n,x);
            n++;
        }
    }
}
