#include<stdio.h>
#include<string.h>
#define maxH 500001


void maxHeapify(int A[],int i,int H){
	int l=i*2;
	int r=l+1;
	int largest=i;
	
	if(l<=H && A[l]>A[i])largest=l;
	if(r<=H && A[r]>A[largest])largest=r;
	
	if(largest!=i){
		int temp=A[i];
		A[i]=A[largest];
		A[largest]=temp;
		maxHeapify(A,largest,H);
	}
}

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

int main(void){
	int A[maxH];
	int cnt=0;
	int key;
	int sort=0;
	char cmd[10];
	
	while(1){
		scanf("%s",cmd);
		if(!strcmp(cmd,"insert")){
			scanf("%d",&key);
			A[++cnt]=key;
			sort=0;
		}else if(!strcmp(cmd,"extract")){
			if(!sort)buildMaxHeap(A,cnt);
			printf("%d\n",A[1]);
			A[1]=A[cnt--];
			maxHeapify(A,1,cnt);
		}else break;
	}
	return 0;
}