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

#define SIZE 2000000

int heap[SIZE];
int n;

void up(int i){
	if( i/2 <= 0 ){ return; }
	if( heap[i/2] > heap[i] ){ return; }
	int temp = heap[i/2];
	heap[i/2] = heap[i];
	heap[i] = temp;
	up(i/2);
	return;
}

void add(int key){
	heap[++n] = key;
	up(n);
	return;
}

void down(int i){
	if( 2*i > n ){
		return;
	}else if( 2*i+1 > n ){
		if( heap[2*i] > heap[i] ){
			int temp = heap[2*i];
			heap[2*i] = heap[i];
			heap[i] = temp;
		}
	}else{
		int j = (heap[i]>heap[2*i]?i:2*i);
		j = (heap[j]>heap[2*i+1]?j:2*i+1);
		if( j == i ){ return; }
		int temp = heap[j];
		heap[j] = heap[i];
		heap[i] = temp;
		down(j);
	}
	return;
}

int extract(){
	int re = heap[1];
	heap[1] = heap[n--];
	down(1);
	return re;
}

int main(){
	int i;
	char com[256];
	while( 1 ){
		scanf("%s", com);
		if( strcmp(com, "end") == 0 ){
			break;
		}else if( strcmp(com, "insert") == 0 ){
			scanf("%d", &i);
			add(i);
		}else if( strcmp(com, "extract") == 0 ){
			printf("%d\n", extract());
		}
	}
	return 0;
}