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

#define comMAX 2000000
#define comLEN 7

void heapify(int s[],int h,int i){
    int l,r,max,tmp;
    l=i*2;
    r=i*2+1;
    max=i;

    if(l<=h&&s[l-1]>s[max-1])max=l;
    if(r<=h&&s[r-1]>s[max-1])max=r;
    
    if(max!=i){
        tmp=s[max-1];
        s[max-1]=s[i-1];
        s[i-1]=tmp;
        
        heapify(s,h,max);
    }
    
    return;
}
void reBuild(int s[],int h){
    int i=1;
    int l,r,max,tmp;
    while(i<=h){
        l=i*2;
        r=i*2+1;
        max=i;
        if(l<=h&&s[l-1]>s[max-1])max=l;
        if(r<=h&&s[r-1]>s[max-1])max=r;
        if(max==i)break;
        tmp=s[i-1];
        s[i-1]=s[max-1];
        s[max-1]=tmp;
        i=max;
    }
}
void output(int s[],int h){
    int i;
    for(i=0;i<h;i++)printf("%d ",s[i]);
    printf("\n");
}

int main(void){
    int i;
    
    int s[comMAX];
    int l=0;
    char com[comLEN+1];
    int x;
    while(1){
        scanf("%s \n",com);
        if(strcmp(com,"insert")==0){
            scanf("%d\n",&x);
            s[l++]=x;
            for(i=l/2;i>0;i--)heapify(s,l,i);
        }else if(strcmp(com,"extract")==0){
            printf("%d\n",s[0]);
            s[0]=s[--l];
            heapify(s,l,1);
        }else if(strcmp(com,"end")==0)break;
        else break;
    }
    
//    output(s,l);
    
    return 0;    
}

