#include <iostream>
#include <string.h>

using namespace std;

struct HEAP{
    int size;
    int length;
    int* array = new int[100];

    HEAP(){
        this->size = 0;
        this->length = 100;
    }

    void double_array(){
        int* arr =  new int[this->length*2];
        for (int i = 1; i < this->size; i++){
            arr[i] = this->array[i];
        }
        delete (this->array);
        this->array = arr;
    }
};

string print(HEAP* heap){
    string aux = "";
    for (int i = 1; i <= heap->size; i++){
        aux += to_string(heap->array[i]) + " ";
    }
    aux += "\n";
    return aux;
}

void heapify (HEAP* heap){
    int n = heap->size, k, v, j;
    //cout << "--------HEAPIFY-------\n";
    for (int i = n/2; i >= 1; i--){
        //cout << print(heap);
        k = i;
        v = heap->array[k];
        bool isHeap = false;

        while(!isHeap && 2*k <= n){
            j = 2*k;
            if (j < n){
                if(heap->array[j] < heap->array[j+1])
                    j++;
            }
            if (v >= heap->array[j])
                isHeap = true;
            else {
                heap->array[k] = heap->array[j];
                k = j;
            }
        }
        heap->array[k] = v;
        //cout << print(heap);
    }
    //cout << "--------HEAPIFY-------\n";
}

void insert (HEAP* heap, int N){
    heap->size++;
    if(heap->size >= heap->length)
        heap->double_array();
    heap->array[heap->size] = N;
    heapify(heap);
}

int remove(HEAP* heap){
    int removed = heap->array[1], aux = heap->array[heap->size];
    heap->array[heap->size] = removed;
    heap->array[1] = aux;
    heap->size--;
    heapify(heap);
    return removed;
}

int main() {

    HEAP* arr = new HEAP();

    string aux = "", answer = "";
    while (aux != "end"){
        getline(cin, aux);

        if (aux.substr(0, 6) == "insert"){
            insert(arr, stoi(aux.substr(7)));
        }else if (aux == "extract"){
            answer += to_string(remove(arr)) + "\n";
        }
    }

    cout << answer.substr(0, answer.length()-1);
    return 0;
}
