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

#define MAX 2000001
#define BOTTOMUP 0
#define TOPDOWN 1

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

void maxHeapify(int *A, int h, int i, int direction) {
	int left, right, largest, next;
	if (i < 1) return;
	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) {
		swap(&A[i], &A[largest]);
		next = direction ? largest : i / 2;
		maxHeapify(A, h, next, direction);
	}
}

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

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

	free(A);

	return 0;
}
