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


#define HEAP_MAX 128

typedef struct _priorityQueue
{
  int heap_size;
  int queue[HEAP_MAX];
} priorityQueue;

void maxHeapify(priorityQueue *, int, int, int);

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

void initPriorityQueue(priorityQueue *pq)
{
  pq->heap_size = 0;
}

int insert(priorityQueue *pq, int key)
{
  int i,j;

  if (pq->heap_size == HEAP_MAX) {
    printf("heap full.\n");
    exit(-1);
  }

  pq->queue[pq->heap_size] = key;
  
  i = pq->heap_size;
  j = (i-1)/2;
  while (i > 0 && j >= 0 && pq->queue[i] > pq->queue[j]) {
    swap(&pq->queue[i], &pq->queue[j]);
    i = j;
    j = (i-1)/2;
  }

  (pq->heap_size)++;

  return 0;
}

void printPriorityQueue(priorityQueue *pq)
{
  int i;
  printf("%d\n", pq->heap_size);
  for (i=0; i<pq->heap_size; i++)
    printf("%d\n", pq->queue[i]);
}

int extractMax(priorityQueue *pq)
{
  int max;

  if (pq->heap_size < 1) {
    perror("heap too short.");
    return -1;
  }

  max = pq->queue[0];
  pq->queue[0] = pq->queue[--(pq->heap_size)];

  maxHeapify(pq, 0, 1, 2);

  return max;
}

// maxHeapify gurantees that heap structure is stil valid.
void maxHeapify(priorityQueue *pq, int i, int l, int r)
{
  int ll, rr, max, maxi;

  //  親ノードの右側の子ノードが存在しなければ無視。
  if (r > pq->heap_size)
    return;

  // 左右の子ノードのうち、大きい方の値と交換する.
  if (pq->queue[i] < pq->queue[l] && pq->queue[i] < pq->queue[r]) {
    max = (pq->queue[l] > pq->queue[r] ? pq->queue[l] : pq->queue[r]);
    maxi = (max == pq->queue[l] ? l : r);
    swap(&pq->queue[maxi], &pq->queue[i]);
    maxHeapify(pq, maxi, 2*maxi+1, 2*maxi+2);
  } else if (pq->queue[i] < pq->queue[l]) {
    swap(&pq->queue[i], &pq->queue[l]);
    maxHeapify(pq, l, 2*l+1, 2*r+2);
  } else if (pq->queue[i] < pq->queue[r]) {
    swap(&pq->queue[i], &pq->queue[r]);
    maxHeapify(pq, r, 2*r+1, 2*r+2);
  }
}

int main(int argc, char const *argv[])
{
  char input[10];
  int n;
  priorityQueue pq;
  initPriorityQueue(&pq);
  
  while (1) {
    scanf("%s", input);
    if (!strcmp(input, "insert")) {
      scanf("%d", &n);
      insert(&pq, n);
    } else if (!strcmp(input, "extract")) {           
      n = extractMax(&pq);
      printf("%d\n", n);
    } else {
      break;
    }  
  }

//  printPriorityQueue(&pq);
  return 0;
}