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

#define MAX 500
#define MIN -1

void maxHeapify(int *A, int h, int i) {
	int left, right, largest, tmp;
	left = i * 2;
	right = left + 1;

	if (left <= h && A[left] > A[i]) largest = left;
	else largest = i;

	if (right <= h && A[right] > A[largest]) largest = right;

	if (largest != i) {
		tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;

		maxHeapify(A, h, largest);
	}
}

void buildMaxHeap(int *A, int h) {
	int i;
	for (i = h / 2; i > 0; i--) {
		maxHeapify(A, h, i);
	}	
}

int main() {
	char order[8];
	int *A = (int *)malloc(sizeof(int) * MAX);
	int h = 0, flg = 1;

	while (flg) {
		scanf("%s", order);
		switch (order[2])
		{
		case 's': //insert
			scanf("%d", &A[++h]);
			break;
		case 't': //extract
			buildMaxHeap(A, h);
			printf("%d\n", A[1]);
			A[1] = MIN;
			break;
		case 'd': //end
			flg = 0;
			break;
		}
	}

	free(A);

	return 0;
}
