#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 2000001

int n=1;

void insert(int *,int);
int extractMax(int  *);
void heapIncreaseKey(int *,int,int);
void my_maxheapify(int *,int);
void my_maxbuild(int *);

int main(){
  int *a,in;
  char input[8];
  a=malloc(sizeof(int)*(N+1));
  while(1){
    scanf("%s",input);
    if(strcmp(input,"insert")==0){
      //INSERT
      scanf("%d",&in);
      insert(a,in);
    }
    if(strcmp(input,"extract")==0){
      //EXTRACT
      extractMax(a);
    }
    if(strcmp(input,"end")==0) break;
  }
  return 0;
}

void my_maxheapify(int *a,int i){
  int l,r,large;
  l=i*2;
  r=i*2+1;
  if(l<=n && a[l]>a[i]) large=l;
  else large=i;
  if(r<=n && a[r]>a[large]) large=r;
  if(large!=i){
    l=a[i];a[i]=a[large];a[large]=l;
    my_maxheapify(a,large);
  }
}

void my_maxbuild(int *a){
  int i;
  for(i=n/2; i>=1; i--){
    my_maxheapify(a,i);
  }
}

void insert(int *a,int k){
  n++;
  a[n]=-9999;
  heapIncreaseKey(a,n,k);
}

int extractMax(int *a){
  if(n<1) return -1;
  int max;
  max=a[1];
  a[1]=a[n];
  n--;
  my_maxheapify(a,1);
  printf("%d\n",max);
  return max;
}

void heapIncreaseKey(int *a,int i,int key){
  int t;
  if(key<a[i]) return;
  a[i]=key;
  while(i>1 && a[i/2]<a[i]){
    t=a[i/2];a[i/2]=a[i];a[i]=t;
    i=i/2;
  }
}

