#include<stdio.h>

int A[2000100];
int size = 0;

void insert(int x)
{
	int i;
	for (i = ++size; i / 2 > 0; i /= 2)
	{
		if (x > A[i / 2])
			A[i] = A[i / 2];
		else
			break;
	}
	A[i] = x;
}

int delete()
{
	int parent, child;
	int x = A[size--], max = A[1];
	for (parent = 1; parent * 2 <= size; parent = child)
	{
		child = 2 * parent;
		if (child != size && A[child + 1] > A[child])
			child++;
		if (x > A[child])
			break;
		A[parent] = A[child];
	}
	A[parent] = x;
	return max;
}

int main()
{
	char s[20];
	int x;
	
	scanf("%s", s);
	while (s[2] != 'd')
	{
		if (s[2] == 's')
		{
			scanf("%d", &x);
			insert(x);
		}
		if (s[2] == 't')
			printf("%d\n", delete());
		scanf("%s", s);
	}
}
