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

#define MAX_HEAP_SIZE   2000000
#define CONTINUE        1
#define STOP            0

int HeapSize;
int Heap[MAX_HEAP_SIZE];

void initVer(void){
    int i;
    
    HeapSize = 0;
    
    for( i = 0; i < MAX_HEAP_SIZE; i++ ){
        Heap[i] = 0;
    }
}

void inputVal(void){
    int i;
    
    scanf("%d",&HeapSize);
    for( i = 1; i <= HeapSize; i++ ){
        scanf("%d",&Heap[i]);
    }
}

void maxHeapify(int Node){
    int LeftNode;
    int RightNode;
    int LargetNode;
    int TmpHeapVal;
    
    LeftNode = 2 * Node;
    RightNode = LeftNode + 1;
    
    if( ( LeftNode <= HeapSize ) && ( Heap[LeftNode] > Heap[Node] ) ){
        LargetNode = LeftNode;
    }else{
        LargetNode = Node;
    }
    
    if( ( RightNode <= HeapSize ) && ( Heap[RightNode] > Heap[LargetNode] ) ){
        LargetNode = RightNode;
    }
    
    if( LargetNode != Node ){
        TmpHeapVal = Heap[Node];
        Heap[Node] = Heap[LargetNode];
        Heap[LargetNode] = TmpHeapVal;
        maxHeapify(LargetNode);
    }
}

void buildMaxHeap(void){
    int i;
    
    for( i = HeapSize / 2; i > 0; i-- ){
        maxHeapify(i);
    }
}

void outputVal(void){
    int i;
    
    for( i = 1; i <= HeapSize; i++ ){
        printf(" %d",Heap[i]);
    }
    printf("\n");
}

void insertVal(int insertval){
    int tmpNode;
    int TmpHeapVal;
    HeapSize++;
    tmpNode = HeapSize;
    Heap[HeapSize] = insertval;
    while(tmpNode > 1 && Heap[tmpNode/2] < Heap[tmpNode]){
        TmpHeapVal = Heap[tmpNode];
        Heap[tmpNode] = Heap[tmpNode/2];
        Heap[tmpNode/2] = TmpHeapVal;
        tmpNode = tmpNode/2;
    }
}

int deleteMaxVal(void){
    int ret;
    ret = -1;
    
    if(HeapSize >= 1){
        ret = Heap[1];
        Heap[1] = Heap[HeapSize];
        HeapSize--;
    }
    return ret;
}

void inputCommand(char *command,int *key){
    scanf("%s",command);
    if(strcmp(command,"insert") == 0){
        scanf("%d",key);
    }
}

int judgeCommand(char *command,int *key){
    int ret;
    int outputVal;
    ret = CONTINUE;
    if(strcmp(command,"insert") == 0){
        insertVal(*key);
    }else if(strcmp(command,"extract") == 0){
        outputVal = deleteMaxVal();
        maxHeapify(1);
        printf("%d\n",outputVal);
    }else if(strcmp(command,"end") == 0){
        ret = STOP;
    }else{
        ;
    }
    return ret;
}

int main(void){
    char command[10];
    int key;
    int roopFlag;
    
    roopFlag = CONTINUE;
    initVer();
    
    while(roopFlag == CONTINUE){
        inputCommand(command,&key);
        roopFlag = judgeCommand(command,&key);
    }
}









