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

/*
 * Aizu - ALDS1_9_C - Priority Queue
 *
 * https://vjudge.net/contest/296407#problem/A
 * https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_9_C
 */

struct heap {
    int capacity;
    int size;
    int *elems;
};

static struct heap *new_heap(int N) {
    struct heap *heap = malloc(sizeof(struct heap));

    heap->capacity = N;
    heap->size = 0;
    heap->elems = malloc(sizeof(int) * N);

    return heap;
}

static int pop(struct heap *heap) {
    int i, s = 0, l, r, v;

    if (heap->size == 0)
        return -1;

    --heap->size;
    v = heap->elems[0];
    heap->elems[0] = heap->elems[heap->size];
    heap->elems[heap->size] = v;

    do {
        i = s;

        if ((l = i * 2 + 1) < heap->size && heap->elems[l] > heap->elems[s])
            s = l;
        if ((r = l + 1) < heap->size && heap->elems[r] > heap->elems[s])
            s = r;

        if (s != i) {
            v = heap->elems[i];
            heap->elems[i] = heap->elems[s];
            heap->elems[s] = v;
        }
    } while (s != i);

    return heap->elems[heap->size];
}

static void push(struct heap *heap, int elem) {
    int i, p, v;

    if (heap->capacity < heap->size + 1) {
        heap->capacity *= 2;
        heap->elems = realloc(heap->elems, sizeof(int) * heap->capacity);
    }

    heap->elems[heap->size++] = elem;

    i = heap->size - 1;

    while (i != 0 && heap->elems[i] > heap->elems[(p = (i - 1) / 2)]) {
        v = heap->elems[i];
        heap->elems[i] = heap->elems[p];
        heap->elems[p] = v;
        i = p;
    }
}

int main() {
    char *op = malloc(8);
    int k;

    struct heap *S = new_heap(2);

    while (scanf("%s", op) == 1 && strcmp("end", op) != 0) {
        if (op[0] == 'i') {
            scanf("%d", &k);
            push(S, k);
        } else {
            printf("%d\n", pop(S));
        }
    }

    return 0;
}

