#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 2000000

void insert(int S[],int k);
void increase(int S[],int i,int k);
int extract(int S[]);
void maxheapify(int S[],int i);

int A[MAX];
int size = 0;

int main()
{
    char a[10];
    int k,l;
    
    while(1){
        scanf("%s",a);
        if(strcmp(a,"end") == 0) break;
        else if(strcmp(a,"insert") == 0){
            scanf("%d",&k);
            insert(A,k);
        }
        else{
            l = extract(A);
            printf("%d\n",l);
        }
    }
    return 0;
}

void insert(int S[],int k)
{
    size = size + 1;
    S[size] = -1;
    increase(S,size,k);
}

void increase(int S[],int i,int k)
{
    int n;
    if(k < S[i]){
        printf("error\n");
        exit(1);
    }
    S[i] = k;
    while(i > 1 && S[i/2] < S[i]){
        n = S[i];
        S[i] = S[i/2];
        S[i/2] = n;
        i = i / 2;
    }
}

int extract(int S[])
{
    int max;
    if(size < 1){
        printf("error\n");
        exit(2);
    }
    max = S[1];
    S[1] = A[size];
    size = size - 1;
    maxheapify(S,1);
    return max;
}

void maxheapify(int S[],int i)
{
    int l,r,largest,n;
    
    l = 2 * i;
    r = 2 * i + 1;
    
    if(l <= size && S[l] > S[i]) largest = l;
    else largest = i;
    
    if(r <= size && S[r] > S[largest]) largest = r;
    if(largest != i){
        n = S[i];
        S[i] = S[largest];
        S[largest] = n;
        maxheapify(S,largest);
    }
}

