#include <stdio.h>
#include <string.h>
#define N 2000001
int parent(int i);
int left(int i);
int right(int i);
void maxHeapify(int);
void insert(int);
void extract(void);
int n=0;
int A[N];
int main(){
  int i;
  char s[10];
  while(1){
    scanf("%s", s);
    if(s[0]=='i'){
      n++;
      scanf(" %d", &A[n]);
      insert(A[n]);
    }
    else if(s[1]=='x') extract();
    else break;
  }   
    return 0;
}
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}  
void maxHeapify(int i){
  int l, r, largest, x;
  l=left(i);
  r=right(i);
  if(l <= n && A[l] > A[i]) largest = l;

  else largest = i;
 
  if(r <= n && A[r] > A[largest]) largest = r;
 
  if(largest != i){
    x=A[i];
    A[i]=A[largest];
    A[largest]=x;
    maxHeapify(largest);
  }
   
}
void insert(int key){
  int i,x; 
  i = n;
  while(i > 1 && A[parent(i)] < A[i]){
    x = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = x;
    i/=2;
  }   
}
 
void extract(void){
  int max; 
  max = A[1];
  A[1] = A[n];
  n--;
  maxHeapify(1);
  printf("%d\n", max);
}