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

#define MAX 2000000

void insert(int *,int);
int extractMax(int *);
void maxHeapify(int *,int);


int size;

int main(){
  int input,i,max;
  char order[8];
  int S[MAX];


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

    if(order[2]=='d')break;

    else if(order[2]=='s'){
      scanf("%d",&input);
      insert(S,input);
      size++;
    }

    else if(order[2]=='t'){
      max=extractMax(S);
      printf("%d\n",max);
    }
  }


  return 0;

}

void insert(int *S,int k){
  int tmp;
  /*if(k < S[k]){
    fprintf(stderr,"new key is smaller than current key\n");
    exit(1);
    }*/
  S[k]=k;
  while(k > 1 && S[k/2] < S[k]){
    tmp=S[k];
    S[k]=S[k/2];
    S[k/2]=tmp;
    k=k/2;
  }

}


int extractMax(int *S){
  int max;
  /* if(size<1){
    fprintf(stderr,"heap underflow");
    exit(2);
    }*/
  max=S[1];
  S[1] = S[size];
  size--;
  maxHeapify(S,1);
  return max;
}

void maxHeapify(int *A,int i){
  int l,r,largest,tmp;
  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){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest);
  }
}  