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

void heapify(int q[],int qCnt,int i){
    int l,r,max;
    l=i*2;
    r=i*2+1;
    max=i;
    
    if(l<=qCnt&&q[l-1]>q[max-1])max=l;
    if(r<=qCnt&&q[r-1]>q[max-1])max=r;
    
    int tmp;
    if(max!=i){
        tmp=q[max-1];
        q[max-1]=q[i-1];
        q[i-1]=tmp;
        
        heapify(q,qCnt,max);
    }
}
void extract(int q[],int qCnt,int i){
    int l,r;
    l=i*2;
    r=i*2+1;
    int tmp;
    
    if(l<=qCnt&&(r>qCnt||q[l-1]>q[r-1])){
        tmp=q[i-1];
        q[i-1]=q[l-1];
        q[l-1]=tmp;
        extract(q,qCnt,l);
    }else if(r<=qCnt&&q[r-1]>q[l-1]){
        tmp=q[i-1];
        q[i-1]=q[r-1];
        q[r-1]=tmp;
        extract(q,qCnt,r);
    }
}
int main(){
    int i;
    char com[7+1];
    int x;
    int q[2000000];
    int qCnt=0;
    
    while(1){
        scanf("%s \n",com);
        if(strcmp(com,"insert")==0){
            scanf("%d\n",&x);
            q[qCnt++]=x;
            for(i=qCnt/2;i>=0;i--)heapify(q,qCnt,i+1);
        }else if(strcmp(com,"extract")==0){
            printf("%d\n",q[0]);
            extract(q,qCnt,1);
            qCnt--;
        }else if(strcmp(com,"end")==0)break;
    }
    
    return 0;
}
