#include<stdio.h>
#include<stdlib.h>
#define K 2000001
#define INF 0.000001

void maxHeapify(int);
void insert(int *,int);
int extractMax(int *);
void Increasekey(int *,int,int);

int S[K];
int A[K];
int h=0;

int main(){
  char order[8];
  int i,key,count=0;

  while(1){
    scanf("%s",order);
    if(order[0]=='i') {
      scanf("%d",&key);
      insert(A,key);
    }
    else if(order[0]=='e' && order[1]=='x') {
        S[count]=extractMax(A);
        count++;
    }
    else break;
  }

  for(i=0;i<count;i++){
    printf("%d\n",S[i]);
  }

  return 0;
}

void maxHeapify(int i){
  int l,r,largest,swap;

  if(h>=2*i)l=2*i; 
  else l=2000000001;  
    
  if(h>=2*i+1) r=2*i+1;
  else r=2000000001;

    if(l<=h && A[l]>A[i]) largest = l;

    else largest = i;

    if(r<=h && A[r]>A[largest]) largest = r;

    if(largest != i) {
       swap = A[i];
       A[i] = A[largest];
       A[largest] = swap;
       maxHeapify(largest);
    }
    else return;

}

int extractMax(int *A){
  int max;
  if(h<1) fprintf(stderr,"heap underflow\n");
 
  max = A[1];
  A[1] = A[h];
  h--;
  maxHeapify(1);

  return max;
}

void insert(int *A,int key){
  h++;
  A[h] = -INF;
  Increasekey(A,h,key);
}

void Increasekey(int *A,int i,int key){
  int swap;

  if(key<A[i]) fprintf(stderr,"new key is smaller than current key\n");
  
  A[i] = key;
  while(i>1 && A[i/2]<A[i]){
    swap = A[i/2];
    A[i/2] = A[i];
    A[i] = swap;
    i = A[1/2];
  }
}


 