#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
int A[2000010],H=0,keys[2000010];
char Command[2000010][10];
void MaxHeapify(int i)
{
	int t;
	int l=2*i;
	int largest;
	int r=2*i+1;
	if(l<=H && A[l]>A[i])
		largest=l;
	else
		largest=i;
	if(r<=H && A[r]>A[largest])
		largest=r;

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

		MaxHeapify(largest);
	}
	return;
}
void heapincreasekey(int i, int key)
{
	int t;
	A[i]=key;
	while(i>1 && A[i/2]<A[i])
	{
		t=A[i];
		A[i]=A[i/2];
		A[i/2]=t;

		i=i/2;
	}
	return;
}
void insert(int key)
{
	H++;
	heapincreasekey(H,key);
}
int heapextractmax()
{
	int max=A[1];
	A[1]=A[H];
	H--;
	MaxHeapify(1);
	return max;
}
int main()
{
	int i=1,j;
	scanf("%s",Command[i]);
	if(Command[1][0]=='i')
		scanf("%d",&keys[i]);
	while(1>0)
	{
		i++;
		scanf("%s",Command[i]);
		if(Command[i][0]=='i')
		scanf("%d",&keys[i]);
		if(strcmp(Command[i],"end")==0)
			break;
	}
	for(j=1;j<=i-1;j++)
	{
		if(Command[j][0]=='i')
			insert(keys[j]);
		if(strcmp(Command[j],"extract")==0)
			printf("%d\n",heapextractmax());
	}


	return 0;
}
