#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 2000000

void maxHeap(int);
int left(int);
int right(int);
void insert(int);
int extract(void);
int parent(int);
void Heapincreace(int,int);

int A[N],c=1;
int main(){
  int i=0,k;
  char C[20];

 
  
  while(1){
    i++;
    scanf("%s",C);
    if(C[0]=='i'){
      scanf("%d",&A[i]);
      insert(A[i]);
      
    }
     
    else if(C[0]=='e'&&C[1]=='x'){
    k=extract();
    printf("%d\n",k);
    }
    else
      break;
  }
  
  return 0;
}


void maxHeap(int i){
  int l,v,r,largest;

  l=left(i);
  r=right(i);

  if(l<=c&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=c&&A[r]>A[largest])
    largest=r;

  if(largest!=i){
    v=A[i];
    A[i]=A[largest];
    A[largest]=v;
    maxHeap(largest);
  }

}
void insert(int i){
  c++;
  A[c]=-270000000;
  Heapincreace(c,i);
}

int extract(){
  int max;
  if(c<1){
    printf("heap underflow");
    exit(8);
  }
  max=A[1];
  A[1]=A[c];
  c--;
  maxHeap(1);
  return max;
}

void Heapincreace(int a,int i){
  int k;
  if(i<A[a]){
    printf("new key is smaller than current key");
    exit(8);
  }
  A[a]=i;
  while(a>1&&A[parent(a)]<A[a]){
    k=A[a];
    A[a]=A[parent(a)];
    A[parent(a)]=k;
    a=parent(a);
  }
}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}