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

#define N 2000000

typedef long int lint;

int size;

void maxHeap(lint H[], int i, int n){
  lint left,right;
  lint largeVal;
  lint temp;
  
  left = i*2;
  right = i*2+1;

  if(left <= n && H[left] > H[i]){
    largeVal = left;
  }
  else{
    largeVal = i;
  }

  if(right <= n && H[right] > H[largeVal]){
    largeVal = right;
  }

  if(largeVal != i){
    temp = H[i];
    H[i] = H[largeVal];
    H[largeVal] = temp;

    maxHeap(H, largeVal, n);
  }
}

void buildMaxHeap(lint H[], int n){
  int i;
  for(i = n/2;i > 0;i--){
    maxHeap(H, i, n);
  }
}

void insert(lint H[], lint key){
  
  H[++size] = key;

  int i = size;
  int temp;
  
  while(i > 1 && H[i] > H[i/2]){
    temp = H[i];
    H[i] = H[i/2];
    H[i/2] = temp;
    i /= 2;
  }
}

void extractMax(lint H[]){
  if(size < 1){
    fprintf(stderr,"cannot extract.\n");
    return;
  }
  
  printf("%ld\n", H[1]);

  H[1] = H[size--];

  maxHeap(H, 1, size);
}

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

  lint H[N+1]={};
  
  while(1){
    scanf("%s",order);

    if(strcmp(order,"insert") == 0){
      scanf("%d",&key);
      insert(H, key);
    }
    else if(strcmp(order, "extract") == 0) extractMax(H);
    else if(strcmp(order, "end") == 0) break;
  }
  return 0;
}

