#include<stdio.h>
#include<string.h>
int heap_size;
int T[2000000];
void maxHeapify(int i){
	int r, l;
	int largest;
	int tmp;
	l=2*i;
	r=2*i+1;
	if( l<= heap_size && T[l]>T[i] ) largest=l;
	else largest=i;
	if( r<=heap_size && T[r]>T[largest] ) largest=r;
	if( largest!=i ){
		tmp=T[i];
		T[i]=T[largest];
		T[largest]=tmp;
		maxHeapify(largest);
	}
}
void buildMaxHeap(void){
	int i;
	for( i=heap_size/2; i>0; i-- ){
		maxHeapify(i);
	}
}
void heapIncreaseKey(int i, int key){
	int tmp;
	if( key<T[i] ) return;
	T[i]=key;
	while( i>1 && T[i/2]<T[i]){
		tmp=T[i];
		T[i]=T[i/2];
		T[i/2]=tmp;
		i=i/2;
	}
}
void maxHeapInsert(int key){
	heap_size=heap_size+1;
	T[heap_size]=-2000000001;
	heapIncreaseKey(heap_size, key);
}
int heapExtractMax(void){
	int max;
	if( heap_size<1 ) return 0;
	max=T[1];
	T[1]=T[heap_size];
	heap_size=heap_size-1;
	maxHeapify(1);
	return max;
}
int main(void){
  char com[20];
  int key;
  while(1){
	  scanf("%s", com);
	  if( strncmp(com,"insert", 6)==0){
		  scanf("%d", &key);
		  maxHeapInsert(key);
	  }
	  else if( strncmp(com,"extract",6)==0){
		printf("%d\n", heapExtractMax());
	  }
	  else if( strncmp(com,"end",3)==0 )break;
  }
  return 0;
}