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

#define MAXH 2000001

void maxHeapify(int *, int, int);
void insert(int *, int, int *);
int extract(int *, int *);
void heapIncreaseKey(int *, int, int);

int main()
{
  int i, key, H = 0;
  int A[MAXH];
  char com[8];

  while(1) {
    scanf("%s",com);
    if(strcmp(com,"end") == 0) break;
    
    if(strcmp(com,"insert") == 0) {
      scanf("%d",&key);
      insert(A,key,&H);
    }
    else if(strcmp(com,"extract") == 0) {
      key = extract(A,&H);
      printf("%d\n",key);
    }
  }

  return 0;
}

void maxHeapify(int *A, int i, int H)
{
  int l, r, largest, tmp;

  l = i*2;
  r = i*2 + 1;

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

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

void insert(int *A, int key, int *H)
{
  (*H)++;  
  heapIncreaseKey(A,key,*H);  
}

int extract(int *A, int *H)
{
  int max;

  max = A[1];

  A[1] = A[*H];
  (*H)--;
  maxHeapify(A,1,*H);

  return max;
}

void heapIncreaseKey(int *A, int key, int i)
{
  int tmp;
  
  A[i] = key;
  while(i > 1 && A[i/2] < A[i]) {
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i /= 2;
  }
}

