#include<stdio.h>
#include<string.h>
#define MAX 2000001
int n;
int a[MAX];
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,tmp;
  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){
    tmp = a[i];
    a[i] = a[largest];
    a[largest] = tmp;
    maxHeapify(largest);
  }
}

int extractMax() 
{
  int max = a[1];
  a[1] = a[n];
  n--;
  maxHeapify(1);
  return max;
}


void increaseKey(int key) 
{
  int i=n;
  int tmp;
  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) 
{
  n += 1;
  a[n] = 0;
  increaseKey(key);
}

int main() 
{
  int i,key;
  char c[10];

  while(1) {
    scanf("%s",c);
    if(!strcmp(c,"insert")) {
      scanf("%d",&key);
      insert(key);
    }
    else if(!strcmp(c,"extract")) printf("%d\n",extractMax());
    else if(!strcmp(c,"end")) break;
  }
  return 0;
}