#include <stdio.h>
#include<stdlib.h>
void maxHeapify(int*,int);
void maxHeapInsert(int*,int);
int maxHeapExtract(int*);
void heapIncreaseKey(int*, int,int);
int n = 0;
int main(void){
    char s[10];
    int i;
    int array[500000];
while(1){
    scanf("%s",s);
    if(s[0] == 'i'){
        scanf("%d",&i);
        maxHeapInsert(array,i);
    }
    else if (s[0] == 'e'){
        printf("%d\n",maxHeapExtract(array));
    }
    else if (s[2] == 'd'){
        break;
    }
}
    return 0;
}
void maxHeapify(int* array, int i){
    int j,largest,l,r;
    l = i * 2;
    r = 2 * i + 1;
    if(l <= n && array[l] > array[i]){
    largest = l;        
    }
    else largest = i;
    if(r <= n && array[r] > array[largest]){
        largest = r;
    }
    if(largest != i){
        j = array[i];
        array[i] = array[largest];
        array[largest] = j;
        maxHeapify(array,largest);
    }
}
void maxHeapInsert(int* array,int i){
    n += 1;
    array[n] = -10000;
    heapIncreaseKey(array,n,i);
}
int maxHeapExtract(int* array){
    int max = 0;
    if (n < 1){
        fprintf(stderr,"heap underflow\n");
       exit(0);
    }
    max = array[1];
    array[1] = array[n];
    n = n - 1;
    maxHeapify(array,1);
    return max;
}
void heapIncreaseKey(int* array, int i,int key){
    int t;
    if(key < array[i]){
        fprintf(stderr,"new key is smaller than old one");
        exit(1);
    }
    array[i] = key;
    while(i > 1 && array[i/2] < array[i]){
        t=array[i];
        array[i] = array[2/i];
        array[2/i] = t;
        i = 2/i;
    }
}