#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define INF -1

int size=0;

int parent(int i){
  return floor(i/2);
}

int left(int i){
  return 2*i;
}

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

void maxHeapify(int *A,int i){
  int l,r,largest,ex;

  l=left(i);
  r=right(i);
  if(l<=size && A[l]>A[i])
    largest=l;
  else largest=i;
  
  if(r<=size && A[r]>A[largest])
    largest=r;
  if(largest!=i){
    ex=A[largest];
    A[largest]=A[i];
    A[i]=ex;
    maxHeapify(A,largest);
  }
}


int heapMaximum(int *A){
  return A[1];
}

int heapExtractMax(int *A){
  int max;
  if(size<1)
    printf("heap underflow\n");
  max=heapMaximum(A);
  A[1]=A[size];
  size--;
  maxHeapify(A,1);
  return max;
}

void heapIncreaseKey(int *A,int i,int key){
  int ex;
  if(key<A[i])
    printf("new key is smaller than current key\n");
  A[i]=key;
  while(i>1 && A[parent(i)]<A[i]){
    ex=A[i];
    A[i]=A[parent(i)];
    A[parent(i)]=ex;
    i=parent(i);
  }
}

void maxHeapInsert(int *A,int key){
  size++;
  A[size]=INF;
  heapIncreaseKey(A,size,key);
}

int main(){
  int *A,k;
  char com[20];
  A=malloc(sizeof(int*)*100000000);
  while(1){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&k);
      maxHeapInsert(A,k);
    }else if(com[0]=='e'){
      if(com[1]=='x'){
        printf("%d\n",heapExtractMax(A));
      }else break;
    }
  }
  return 0;
}

