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

#define MAX 1000000


int parent(int i) {return i / 2;}
int left(int i) {return 2*i;}
int right(int i){return 2*i + 1;}
int H = 0;
int A[MAX];



void insert(int k){
    A[++H] = k;

    int large;

    /* rootの時は普通に通過 */
    if(H != 1){
        if(A[H] > A[parent(H)]){
            large = H;
        } else{
            large = parent(H);
        }

        if(large == H){
            int i = large;
            while(i > 1 && A[i] > A[parent(i)]){
                int tmp = A[parent(i)];
                A[parent(i)] = A[i];
                A[i] = tmp;
                i = parent(i);
            }
        }

    }
    
}

void extract(){
    
    int now = 1;
    int large = 0;
    printf("%d\n", A[1]);
    
    /* 最下層に到達するまで */
    while(left(now) <= H){
        if(right(now) <= H){
            if(A[right(now)] < A[left(now)]){
                large = left(now);
            } else{
                large = right(now);
            }
        } else{
            large = left(now);
        }

        /* swap */
        int tmp = A[now];
        A[now] = A[large];
        A[large] = tmp;
        now = large;

    }

    while(now <  H){
        A[now] = A[now + 1];
        now++;
    }

    if(H > 1){
        H--;
    }

    
}

int main(){
    int cnt = 0, i;
    while(1){
        char com[10];
        int v;
        scanf("%s", com);
        if(com[0] == 'i'){
            scanf("%d", &v);
            insert(v);
            cnt++;
        } else if(strlen(&com[0]) == 3){
            break;
        } else {
            extract();
        }
    }

    
    return 0;
}
