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

#define MAX 2000000000
#define INFTY -1

int H;
int A[MAX+1];

void maxHeapify(int);
int extract(void);
void IncreaseKey(int ,int );
void insert(int);

int main(){
	int key;
	char com[10];

	while(1){
		scanf("%s",com);

		if(strcmp(com,"end") == 0) break;
		if(strcmp(com,"insert") == 0){
			scanf("%d",&key);
			insert(key);
		}
		else{
			printf("%d\n",extract());
		}
	}
	return 0;
}

void maxHeapify(int z){
  int right, left, largest;
  int tmp;
  left = 2 * z;
  right = 2 * z + 1;

	//keyが最大のノードを選ぶ
  if(left <= H && A[left] > A [z]) largest = left;
  else largest = z;
  if(right <= H && A[right] > A[largest]) largest = right;

  if(largest != z){
    tmp = A[z];
    A[z] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}


int extract(){
	int maxv;
	if(H < 1) return INFTY;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void IncreaseKey(int i,int key){
int tmp;

	if(key < A[i]) return;
	A[i] = key;
	while(i > 1 && A[i / 2] < A[i]){
	 //A[i]とA[i / 2]を交換
	 	tmp = A[i];
		A[i] = A[i / 2];
		A[i / 2] = tmp;
		i = i / 2;
	}
}

void insert(int key){
	H++;
	A[H] = INFTY;
	IncreaseKey(H,key);
}

