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

#define MAX 2000000

void MaxHeap(int*,int);
int Insert(int*,int);
int Extract(int*);

int h=0;

int main(void){
  int S[MAX],key=0;
  char states[8];

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

    if(!strcmp(states, "end")) break;
    else if(!strcmp(states, "insert")){
      scanf("%d", &key);
      Insert(S, key);
    } else if(!strcmp(states, "extract")){
      Extract(S);
    }

  }

  return 0;
}

int Insert(int *S, int key){
  int i, tmp;

  h++; i = h;
  S[i] = key;

  while(i > 1 && S[i/2] < S[i]){
    tmp = S[i];
    S[i] = S[i/2];
    S[i/2] = tmp;
    i = i/2;
  }

  return;
}

int Extract(int *S){
  int max;

  max = S[1]; S[1] = S[h];
  h--;

  MaxHeap(S, 1);
  printf("%d\n", max);

  return;
}

void MaxHeap(int *S, int i){
  int left, right, large, tmp;

  if(i*2 <= h) left = i*2;
  else left = i;

  if(i*2+1 <= h) right = i*2+1;
  else right = i;

  if(left < h+1 && S[left] && S[left] > S[i]) large = left;
  else large = i;

  if(right < h+1 && S[right] > S[large]) large = right;

  if(large != i){
    tmp = S[i];
    S[i] = S[large];
    S[large] = tmp;
    MaxHeap(S, large);
  }

    return;
}