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


int HeapSize; 
void swap(int *a,int *b)
{
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}


void maxHeapify(int *A,int i)
{
  int l, r, largest;
  l= i*2;
  r = i*2+1;
  if(l <= HeapSize && A[l] > A[i])
    largest = l;
  else
    largest = i; 

  if(r <= HeapSize && A[r] > A[largest])
    largest = r;
  
  if(largest != i)
  {
    swap(&A[i],&A[largest]);
    maxHeapify(A,largest);
  }
}


int hExMax(int *A)
{
  int max;
  if(HeapSize < 1)
      return -1; 
  max = A[0];
  A[0] = A[HeapSize-1]; 
  HeapSize--;
  maxHeapify(A,0);
  return max;
}

void hIncKey(int *A,int i,int key)
{
  int j;
  if(key < A[i])
      return; 
    A[i] = key;
    if(i!=0 & 1)
        j = i/2; 
    else
        j = (i-1)/2;
  while(i > 0 && A[j] < A[i]){
    swap(&A[i],&A[j]);
    i = j;
    if(i!=0 & 1)
        j = i/2; 
    else
        j = (i-1)/2;
  }
}


void maxHInsert(int *A,int key)
{
  HeapSize++;
  A[HeapSize-1] =  INT_MIN;
  hIncKey(A,HeapSize-1,key);
}

int main(){
  int key;
  int A[2000000];
  char op[8];
  HeapSize = 0;
  int res=0;
  while(1)
  {
    scanf("%s", op);
    
    if(!strcmp(op,"insert"))
    {
      scanf("%d",&key);
      maxHInsert(A,key);
    }
    if(!strcmp(op,"extract"))
    {
        res = hExMax(A);
      printf("%d\n",res);
    }
    if(!strcmp(op,"end"))
    {
      break;
    }
  }
  return 0;
}

