function swap(A, i, j) {
	var tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
}
function parent(i) {
	return Math.floor(i / 2);
}
function left(i) {
	return i * 2;
}
function right(i) {
	return i * 2 + 1;
}
function maxHeapify(A, i) {
	var l = left(i);
	var r = right(i);

	var largest;
	if (l <= heap.length && A[l] > A[i]) {
		largest = l;
	} else {
		largest = i;
	}
	if (r <= heap.length && A[r] > A[largest]) {
		largest = r;
	}

	if (largest != i) {
		swap(A, i, largest);
		maxHeapify(A, largest);
	}
}
function insert(A, key) {
	A[heap.length] = Number.NEGATIVE_INFINITY;
	increaseKey(A, heap.length, key);
}
function increaseKey(A, i, key) {
	A[i] = key;
	while (i > 1 && A[parent(i)] < A[i]) {
		swap(A, i, parent(i));
		i = parent(i);
	}
}
function extractMax(A) {
	var max = A[1];
	A[1] = A.pop();
	maxHeapify(A, 1);
	return max;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');

var heap = ['NA'];
var command;
while ((command = lines.shift()) != 'end') {
	var arr = command.split(' ');
	if (arr[0] == 'insert') {
		insert(heap, +arr[1]);
	} else {
		var val = extractMax(heap);
		console.log(val);
	}
}