#include <stdio.h>

int H=0;

void maxHeapify(int *A,int i){
    int l=2*i,r=l+1,max;
    if(l<=H && A[l]>A[i]) max=l;
    else max=i;
    if(r<=H && A[r]>A[max]) max=r;

    if(max!=i){
        int t=A[i];
        A[i]=A[max];
        A[max]=t;
        maxHeapify(A,max);
    }
}

void buildMaxHeap(int *A){
    int i;
    for(i = H/2;i>0;i--)
        maxHeapify(A, i);
}

int main(void){
    int S[2000000];
    char command[10];
    while(scanf("%s",command)!=EOF){
        if(command[2]=='d') break;
        else if(command[2]=='s'){
            int k;
            scanf("%d",&k);
            S[H++]=k;
        }
        else if(command[2]=='t'){
            buildMaxHeap(S);
            printf("%d\n",S[1]);
            S[1]=-1;
        }
    }
    return 0;
}
