#include <stdio.h>
#define MIN -1000000000
int heapsize=0,A[2000000001];
void buildMapHeap();
void maxHeapify(int );
void insert(int );
void helpIncreaseKey(int ,int );
int heapExtractMax(int );


int main(void){
  int key;
  char command[7];
  while(1){
    scanf("%s",command);
    if(command[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(command[0]=='e'){
      if(command[1]=='n')
	break;
      else if(command[1]=='x')
	printf("%d\n",helpExtractMax());
    }
  }
  
  return 0;
}

int helpExtractMax(int element){
  int max;
  if(heapsize<1)
    return ;
  max=A[1];
  A[1]=A[heapsize];
  heapsize--;
  maxHeapify(1);
  return max;
}

void helpIncreaseKey(int element,int key){
  int temp;
  if(key < A[element])return ;
  A[element]=key;
  while(element>1 && A[element/2] < A[element]){
    //
    temp=A[element];
    A[element]=A[element/2];
    A[element/2]=temp;
    element/=2;
  }
}

void insert(int key){
  heapsize++;
  A[heapsize]=MIN;
  //set key to A[heapsize]
  helpIncreaseKey(heapsize,key);
}

void buildMapHeap(){
  int i;
  for(i=heapsize/2;i>=1;i--)
    maxHeapify(i);
}
void maxHeapify(int parent){
  int left,right,maxnode,temp;
  left=2*parent;
  right=left+1;

  if(left<=heapsize && A[left] > A[parent])
    maxnode=left;
  else
    maxnode=parent;
  if(right<=heapsize && A[right] > A[maxnode])
    maxnode=right;

  if(maxnode!=parent){
    //need to swap node
    temp=A[maxnode];
    A[maxnode]=A[parent];
    A[parent]=temp;

    if(maxnode*2<=heapsize)
      //there is child of maxnode
      maxHeapify(maxnode);
  }
}

