#include <stdio.h>

int main(void){
    int max=-1,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);
            if(max==-1) S[++max]=k;
            else{
                int p=++max;
                while(p>0 && S[p-1]>k){
                    S[p]=S[p-1];
                    p--;
                }
                S[p]=k;
            }
        }
        else if(command[2]=='t'){
            printf("%d\n",S[max]);
            S[max--]=-1;
        }
    }
    return 0;
}
