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

#define INF -1

void maxHeapInsert(int*,int);
void HeapIncreaseKey(int*,int,int);
int HeapExtractMax(int*);
void maxHeapify(int*,int);

int size=0;

int main(){

  int k=2000000,i,num,A[2000001],count=0,max;
  char order[8];

  for(i=0;i<k;i++){
    
    scanf("%s",order);

    if(strcmp(order,"insert")==0){

      scanf("%d",&num);

      maxHeapInsert(A,num);

    }

    else if (strcmp(order,"extract")==0){

      max=HeapExtractMax(A);
      printf("%d\n",max);
      
    }

    else if(strcmp(order,"end")==0){
      count+=1;
    }
    
    if(count==1) break;
   
  }
  
  return 0;
}

void maxHeapInsert(int A[],int key){

  size=size+1;
  A[size]=INF;
  HeapIncreaseKey(A,size,key);
  //printf("%d\n",A[size]);

}

void HeapIncreaseKey(int A[],int i,int key){

  int change;

  if(key < A[i]) printf("new key is smaller than current key\n");

  A[i]=key;
  
  while( i > 1 && A[i/2] < A[i] ){

    change=A[i];
    A[i]=A[i/2];
    A[i/2]=change;
    i=i/2;

  }

}

void maxHeapify(int A[],int i){

  int l,r,largest,change;

  //printf("i:%d\n",i);
  
  l=2*i;
  r=2*i+1;

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

  if(r<=size && A[r] > A[largest]) largest = r;
  
  if(largest !=i){

    change = A[i];
    A[i]=A[largest];
    A[largest]=change;
    maxHeapify(A,largest);
  }


}

int HeapExtractMax(int A[]){

  int max;
  
  if(size<1) printf("heap underflow\n");

  max = A[1];

  A[1]=A[size];
  size--;
  maxHeapify(A,1);
  return max;

}