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

typedef int HeapElementType;
typedef bool (*CompareFunc)(HeapElementType, HeapElementType);

typedef struct {
  HeapElementType* heap;
  unsigned int size;
  unsigned int maxSize;
  CompareFunc cmp;
} PriorityQueue;

void heapify(HeapElementType*, unsigned int, CompareFunc, unsigned int);
bool compare(HeapElementType, HeapElementType);

void insert(PriorityQueue*, HeapElementType);
HeapElementType extract(PriorityQueue*);

int main () {
  int k;
  char command[10];
  PriorityQueue pQueue;

  pQueue.maxSize = 1;
  pQueue.heap = (HeapElementType*)malloc(sizeof(HeapElementType)*(pQueue.maxSize + 1));
  pQueue.size = 0;
  pQueue.cmp  = compare;

  while (true) {
    scanf("%s", command);
    if (!strcmp(command, "insert")) {
      scanf("%d", &k);
      insert(&pQueue, k);
    } else if (!strcmp(command, "extract")) {
      k = extract(&pQueue);
      printf("%d\n", k);
    } else {
      break;
    }
  }
  
  return 0;
}

bool compare (HeapElementType x, HeapElementType y) {
  return x > y;
}

void heapify (HeapElementType* heap, unsigned int H, CompareFunc cmp, unsigned int i) {
  unsigned int left  = 2*i;
  unsigned int right = 2*i + 1;

  unsigned int target;
  if (left <= H && cmp(heap[left], heap[i])) {
    target = left;
  } else {
    target = i;
  }

  if (right <= H && cmp(heap[right], heap[target])) {
    target = right;
  }

  if (target != i) {
    HeapElementType t = heap[i];
    heap[i] = heap[target];
    heap[target] = t;
    heapify(heap, H, cmp, target);
  }
}

void insert (PriorityQueue* pQueue, HeapElementType key) {
  pQueue->size++;
  if (pQueue->size > pQueue->maxSize) {
    pQueue->maxSize <<= 2;
    pQueue->heap = (HeapElementType*)realloc(pQueue->heap, sizeof(HeapElementType)*(pQueue->maxSize + 1));
  }

  pQueue->heap[pQueue->size] = key;

  unsigned int target = pQueue->size;
  while (target >= 2) {
    unsigned int parent = target/2;
    if (pQueue->cmp(pQueue->heap[parent], pQueue->heap[target])) {
      break;
    } else {
      HeapElementType t = pQueue->heap[parent];
      pQueue->heap[parent] = pQueue->heap[target];
      pQueue->heap[target] = t;
      target = parent;
    }
  }
}

HeapElementType extract (PriorityQueue* pQueue) {
  int key = pQueue->heap[1];
  pQueue->heap[1] = pQueue->heap[pQueue->size];
  pQueue->size--;  
  heapify(pQueue->heap, pQueue->size, pQueue->cmp, 1);

  return key;
}

