import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.container;

void main()
{
  auto hi = new int[](2_000_001);
  auto h = 1;

  for (;;) {
    auto rd = readln.chomp.splitter(' '), cmd = rd.front;
    switch (cmd) {
    case "insert":
      rd.popFront;
      hi[h++] = rd.front.to!int;
      break;
    case "extract":
      buildMaxHeap(hi, h);
      writeln(hi[1]);
      hi = hi[1..$];
      --h;
      break;
    case "end":
      return;
    default:
      assert(0);
    }
  }
}


void maxHeapify(ref int[] ai, size_t h, size_t i)
{
  auto l = i * 2, r = l + 1;
  size_t largest;

  if (l <= h && ai[l] > ai[i])
    largest = l;
  else
    largest = i;
  if (r <= h && ai[r] > ai[largest])
    largest = r;

  if (largest != i) {
    swap(ai[i], ai[largest]);
    maxHeapify(ai, h, largest);
  }
}

void buildMaxHeap(ref int[] ai, size_t h)
{
  foreach_reverse(i; 1..h/2+1)
    maxHeapify(ai, h, i);
}