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

#define N 2000000

int A[N];
int H;

void maxHeapify(int);
void build();
void swap(int *, int *);

int main(){
  char com[10];
  int i, num, e=0;

  while(1){
    scanf("%s",com);

    switch(com[0]){
    case 'i':
      scanf("%d",&num);
      H++;
      A[H] = num;

      i=H;
      while(i > 1 && A[i/2] < A[i]){
    swap(&A[i/2], &A[i]);
    i = i/2;
      }

      break;

    case 'e':
      if(com[1] == 'x'){
    printf("%d\n",A[1]);

    A[1] = A[H];
    H--;

    maxHeapify(1);
      }

      if(com[1] == 'n')
    e++;

    break;
    }

    if(e>0)
      break;
  }
}

void maxHeapify(int i){
  int l = 2*i;
  int r = 2*i + 1;
  int largest;

  if(l <= H && A[l] > A[i])
    largest = l;

  else
    largest = i;

  if(r <= H && A[r] > A[largest])
    largest = r;

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

void build(){
  int i;

  for(i=H/2; i>0; i--)
    maxHeapify(i);
}

void swap(int *a, int *b){
  int t;

  t = *a;
  *a = *b;
  *b = t;
}

