#include <stdio.h>
#include <string.h>
#define SIZE 2000000
#define INF 30
int n,hi[SIZE+1];

void maxHeapify(int i);
void increasekey (int i,int p);
void insert (int p);
int extract ();
int main(){
  int key;
  char hi[10];

  while(1){
    scanf("%s",hi);
    if(hi[0]=='e' && hi[1]=='n') break;
    if(hi[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }else{
      printf("%d\n",extract());
    }
  }

  return 0;
}

void maxHeapify(int i){
  int l,r,max,tem;
  l=2*i;
  r=2*i+1;
  
  if(l<=n && hi[l]>hi[i]){
    max=l;
  }
  else max=i;
  if(r<=n && hi[r]>hi[max]){
    max=r;
  }
  if(max != i){
    tem =hi[i]; 
    hi[i]=hi[max];
    hi[max]=tem;
    maxHeapify(max);
  }
}

void increasekey (int i,int p){
  int tem;
  hi[i]=p;
  while(i>1 && hi[i/2]<hi[i]){
    tem =hi[i]; 
    hi[i]=hi[i/2];
    hi[i/2]=tem;

    i=i/2;
  }
}

void insert (int p){
  n++;
  hi[n]=-INF;

  increasekey(n,p);
}

int extract (){
  int a;
  if(n<1)
    return -INF;

  a=hi[1];
  hi[1]=hi[n--];
  
  maxHeapify(1);

  return a;
}
  

