#include<stdio.h>
#define N 2000000

int H[N];
int top=0;

void swap(int a,int b){
	int temp=H[a];
	H[a]=H[b];
	H[b]=temp;
	return;
}

void up_to_heap(){
	
	int i=top-1;
	while(i>0){
		if(i%2==0){
			if(H[i] > H[i/2-1]){
				swap(i,i/2-1);
				i=i/2-1;
			}
			else break;
		}
		else {
			if(H[i] > H[i/2]){
				swap(i,i/2);
				i=i/2;
			}
			else break;
		}
	}
	return;

}

int is_leaf(int i){
	if(top/2 <= i && i < top)return 1;
	return 0;
}

void down_to_heap(){
	int i=0;
	
	while(!is_leaf(i)){
		if(i*2+1==top-1){
			if(H[i] < H[i*2+1]){
				swap(i,i*2+1);
				break;
			}
		}
		else {
			if(H[i*2+1] < H[i*2+2]){
				if(H[i] <H[i*2+2]){
					swap(i,i*2+2);
					i=i*2+2;
				}
				else break;
			}
			else {
				if(H[i] < H[i*2+1]){
					swap(i,i*2+1);
					i=i*2+1;
				}
				else break;
			}
		}
	}
	
	return;
	
}

void extractMax(){
	printf("%d\n",H[0]);
	swap(0,top-1);
	top--;
	down_to_heap();
	return;
}


void insert(int x){
	H[top++]=x;
	up_to_heap();
	
	return;
}

int main(){
	char com[10];
	int x;
	
	while(scanf("%s",com)!=EOF){
		if(com[2]=='d')break;
		
		if(com[0]=='i'){
			scanf("%d",&x);
			insert(x);
		}
		
		if(com[1]=='x')
			extractMax();
	}
	
	return 0;
	
}
