#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 2000000
#define INF 2000000000
int size;
int A[N];
int left(int i){
  return (i*2);
}
int right(int i){
  return (i*2+1);
}
int parent(int i){
  return floor(i/2);
}

void increase(int i,int key){
  int tmp;
  if(key<A[i]) return;
  A[i] = key;
  while(i>1 && A[parent(i)]<A[i]){
    tmp=A[i];
    A[i]=A[parent(i)];
    A[parent(i)]=tmp;
    i = parent(i);
  }
}

void insert(int key){
  size+=1;
  A[size]=-INF;
  increase(size,key);
}

void Heapify(int i){
  int l,r,tmp;
  int largest;
  l = left(i);
  r = right(i);
  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;
    Heapify(largest);
  }
}
int extract(){
  int max;
  if(size<1) return;
  max = A[1];
  A[1] = A[size];
  size-=1;
  Heapify(1);
  return max;
}

int main(){
  char com[100];
  int x,i;
  int A[N];
  size=0;
  while(com[2]!='d'){
    scanf("%s",com);
    if(com[0] == 'i' ){
      scanf("%d",&x);
      insert(x);
    }
    else if (com[1] == 'x'){
      printf("%d\n",extract());
    }
  }
  return 0;
}