#include<stdio.h>
#include<string.h>

#define N 2000000

void maxHeapify(int A[],int j); 
void buildMaxHeap(int B[]);
void maxHeapInsert(int C[],int x);
void heapIncreaseKey(int D[],int m,int y);
int heapExtractMax(int E[]);

int n;
int s=1;//
int P[N];//

int main(){
	char com[20];
	int node[N];
	int i,key;
	n=1;

	while(1){
		scanf("%s",com);
		if(com[0]=='i'){
			scanf("%d",&key);
			maxHeapInsert(node,key);
		}
		else if(com[0]=='e'){
			if(com[1]=='x')heapExtractMax(node);
			else break;
		}
	}

	for(i=1;i<s;i++)printf("%d\n",P[i]);

	return 0;
}

void maxHeapify(int A[],int j){
	int left,right,largest,key;

	left=2*j;
	right=left+1;
	if(left<=n && A[left]>A[j])largest=left;
	else largest=j;

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


	if(largest!=j){
		key=A[j];
		A[j]=A[largest];
		A[largest]=key;
		maxHeapify(A,largest);
	}
}

void buildMaxHeap(int B[]){
	int i;
	for(i=n/2;i>0;i--)maxHeapify(B,i);
}

void maxHeapInsert(int C[],int x){
	n=n+1;
	C[n]=-1;
	heapIncreaseKey(C,n,x);
}
void heapIncreaseKey(int D[],int m,int y){
	int key;
	if(y<D[m])printf("error\n");
	D[m]=y;
	while(m>1 && D[m/2]<D[m]){
		key=D[m/2];
		D[m/2]=D[m];
		D[m]=key;
		m=m/2;
	}
}
int heapExtractMax(int E[]){
	int max;
	if(n<1)return -1;
	max=E[1];
	E[1]=E[n];
	n=n-1;
	maxHeapify(E,1);
	P[s]=max;//
	s++;//
	return max;
}