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

#define MINint -2147483648

void heapIN(int,int);
void insert(int);
int extract(void);
void Mheap(int);

int H=0,A[2000000];

int main(){
  int i,a;
  char buffer[7];

  while(1){
    scanf("%s",buffer);
    if(buffer[2]=='s') {
      scanf("%d",&a);
      insert(a);
    //  for(i=1;i<H;i++)printf(" %d",A[i]);
    //  printf("\n");
    }
    else if(buffer[2]=='t') printf("%d\n",extract());
    else if(buffer[2]=='d') break;
  }

    return 0;
}

void insert(int k){
  H++;
  A[H]=MINint;
  heapIN(H,k);
}

void heapIN(int i,int k){
  int swap;

    if (k<A[i]) return;
    A[i]=k;

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

int extract(){
  int max;

  if(H<1) return A[0];
  max=A[1];
  A[1]=A[H];
  H--;
  Mheap(1);

  return max;
}

void Mheap(int i){
  int l,r,largest,swap;

  l = i*2;
  r = i*2+1;

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

  if(largest != i){
    swap=A[largest];
    A[largest]=A[i];
    A[i]=swap;

    Mheap(largest);
  }
}


    
  

