#include<stdio.h>
#define MAX 2000001
#define INF 200000000
int left(int);
int right(int);
void buildMaxHeap();
void maxHeapify(int);
void maxHeapInsert(int);
int parent(int);
void heapIncreaseKey(int, int);
int extract();

int A[MAX];
int n;

void maxHeapify(int i){
  int largest,l,r,tmp;
  l = left(i);
  r = right(i);
   
  if (l<=n && A[l]>A[i])  largest = l;
  else  largest = i;
  
  if(r<=n && A[r]>A[largest])  largest = r;
  if (largest != i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}
int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}
int parent(int i){
  return i/2;
}

void buildMaxHeap(){
  int i;  
  for(i=n/2;i>0;i--) maxHeapify(i);
}
	  
void maxHeapInsert(int k){
  n++;
  A[n] = -INF;
  heapIncreaseKey(n,k);
}
 
void heapIncreaseKey(int i, int k){
   int temp;
   
  A[i] = k;
  while(i>1 && A[parent(i)] < A[i]){
    temp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = temp;
    i = parent(i);
  }   
}
int extract(){
  int max = A[1];
  A[1] = A[n];
  n--;
  maxHeapify(1);
   
  return max;
}

     
int main(){
  int n,i;
  char C[10];

 
  while(1){
    scanf("%s",C);
    
    if(C[2]=='s'){
      scanf("%d",&n);
      maxHeapInsert(n);
    }
    else if(C[2] == 't'){
      printf("%d\n",extract());
    }
    else if(C[2]=='d'){
      break;
    }
  }
  return 0;
}