#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 2000000

void insert(int);
void heapIncreasekey(int *, int, int);
int heapextractMax(int *);
void maxheap(int *, int);

int heap[N+1], A[N+1], size=0;

int main(){

  int i, k, count=0;
  char command[8];

  while(1){
    scanf("%s",command);
    if(strlen(command)==3) break;
    else if(command[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(command[0]=='e'){
      A[count]=heapextractMax(heap);
      count++;
    }
  }
  for(i=0;i<count;i++){
    printf("%d\n",A[i]);
  }
  return 0;
}

void insert(int k){
  size++;
  heap[size]=-1;
  heapIncreasekey(heap, size, k);
}

void heapIncreasekey(int *heap, int i, int k){
  int t;

  if(k<heap[i]) return;
  heap[i]=k; 
  while(i>1 && heap[i/2]<heap[i]){
     t=heap[i];
     heap[i]=heap[i/2];
     heap[i/2]=t;
     i/=2;
  }
}

int heapextractMax(int *heap){
  int max;

  if(size<1) return 0;
  max=heap[1];
  heap[1]=heap[size];
  size--;
  maxheap(heap, 1);
  return max;
}
    
void maxheap(int *heap, int i){
  int l=2*i, r=2*i+1, largest, t;

  if(l<=size && heap[l]>heap[i]) largest=l;
  else largest=i;
  if(r<=size && heap[r]>heap[largest]) largest=r;
  if(largest!=i){
    t=heap[i];
    heap[i]=heap[largest];
    heap[largest]=t;
    maxheap(heap, largest);
  }
}

    




  
  
  
  
