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

void max_heapify(int *heap, int i) {
	int hsize, L, R, large, tmp;

	hsize = heap[0];
	L = 2 * i;
	R = 2 * i + 1;

	if (L <= hsize && heap[L] > heap[i]) {
		large = L;
	}
  else {
		large = i;
	}

	if (R <= hsize && heap[R] > heap[large]) {
		large = R;
	}

	if (large != i) {
		tmp = heap[i];
		heap[i] = heap[large];
		heap[large] = tmp;
		max_heapify(heap, large);
	}
}

int main(void) {
	int *heap, key, index, half, tmp;
	char com[20];

	heap = malloc(sizeof(int) * 2000001);
	heap[0] = 1;
	while (1) {
		scanf("%s %d ", com, &key);
		if (com[0] == 'i') {
			heap[0]++;
			index = heap[0];
			heap[index] = key;

			half = index / 2;
			while (index > 1 && heap[half] < heap[index]) {
				tmp = heap[index];
				heap[index] = heap[half];
				heap[half] = tmp;
				index /= 2;
				half = index / 2;
			}
		}
    else if (com[1] == 'x') {
			printf("%d\n", heap[1]);
			heap[1] = heap[heap[0]];
			heap[0]--;
			max_heapify(heap, 1);
		}
    else {
			return 0;
		}
	}

	return 0;
}

