#include<stdio.h>
#define N 20000001
int extract(void);
void insert(int);
void increase(int,int);
void maxHeapify(int i);
int A[N];
int main(){
  char s[10];
  int num;
  A[0]=0;
  while(1){
    scanf("%s",s);
    switch(s[2]){
    case 's':
      scanf("%d",&num);
      insert(num);
      break;
    case 't':
      printf("%d\n", extract());
      break;
    case 'd':
      goto END;
      break;
    }
  }
 END:
  return 0;
}
void insert(int num){
  A[0]++;
  increase(A[0],num);
  
}
int extract(){
  int max=A[1];
  A[1]=A[A[0]];
  A[0]--;
  maxHeapify(1);
  return max;
}
void maxHeapify(int i){
  int l,r,H,largest;
  l=i*2;
  r=i*2+1;

  if(l<=A[0]&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=A[0]&&A[r]>A[largest])
    largest=r;
  if(largest!=i){
    H=A[i];
    A[i]=A[largest];
    A[largest]=H;
    maxHeapify(largest);
  }
}
void increase(int i,int key){
  int c;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    c=A[i/2];
    A[i/2]=A[i];
    A[i]=c;
    i=i/2;
  }
}

