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

int A[2000001],H=0;
void maxHeapify(int *A,int i){
  int largest,l,r,tmp;
  l = 2*i;
  if(2*i+1 <= H)r = 2*i+1;
  else r = NULL;
  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest] && r != NULL)largest = r;

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;
  for(i=H/2;i>0;i--)maxHeapify(A,i);
}

void insert(int *A,int k){
  int i,tmp;
  H++;
  i = H;
  A[i] = k;
  while(A[i] > A[i/2] && i/2 > 0){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

int extractMax(int *A){
  int a;
  if(H<1)exit(2);
  a = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(A,1);
  return a;
}

int main(){
  int i,x;
  char c[20];
  while(1){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&x);
      insert(A,x);
    }
    else if(c[0]=='e'){
      if(c[1]=='x')
	printf("%d\n",extractMax(A));
      else if(c[1]=='n')
	break;
    }
  }

  return 0;
}

