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

#define N 2000000

int heap[N], H;

void swap(int *a, int *b) {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

int right(int id) {
    return (2 * id) + 1;
}

int left(int id) {
    return 2 * id;
}

int parent(int id) {
    return id / 2;
}

int max() {
    return 1;
}

void maxHeapify(int id) {
    int largest = id;

    if (left(id) <= H && heap[left(id)] > heap[largest]) {
        largest = left(id);
    }
    if (right(id) <= H && heap[right(id)] > heap[largest]) {
        largest = right(id);
    }

    if (largest != id) {
        swap(&heap[largest], &heap[id]);
        maxHeapify(largest);
    }
}

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

int heapExtractMax() {
    int result;

    if (H < 1) {
        printf("error\n");
        exit(1);
    }
    result = heap[max()];
    heap[max()]= heap[H];
    H--;
    maxHeapify(max());
    return result;
}

void heapIncreaseKey(int id, int key) {
    if (key < heap[id]) {
        return;
    }

    heap[id] = key;
    while (id > 1 && heap[parent(id)] < heap[id]) {
        swap(&heap[id], &heap[parent(id)]);
        id = parent(id);
    }
}

void heapInsertMax(int key) {
    H++;
    heap[H] = -1;
    heapIncreaseKey(H, key);
}

int main() {
    int i, input;
    char op[10];

    while (1) {
        scanf("%s", op);

        if (strcmp(op, "insert") == 0) {
            scanf("%d", &input);
            heapInsertMax(input);
        }
        if (strcmp(op, "extract") == 0) {
            scanf("%d", &input);
            printf("%d\n", heapExtractMax());
        }
        if (strcmp(op, "end") == 0) {
            break;
        }
    }

    return 0;
}
