#include <stdio.h>
#include <limits.h>
#define exchange(a,b) do{__typeof(a) __t; __t=a; a=b; b=__t;}while(0)
#define parent(i) (i/2)
#define left(i) (i*2)
#define right(i) (i*2+1)
#define MAX_N 2000002

int N;
int heap[MAX_N];

void maxHeapify(int A[], int i) {
  int l = left(i);
  int r = right(i);
  int largest;
  if(l <= N && A[l] > A[i]) {
    largest = l;
  } else {
    largest = i;
  }
  if(r <= N && A[r] > A[largest]) {
    largest = r;
  }
  if(largest != i) {
    exchange(A[i], A[largest]);
    maxHeapify(A, largest);
  }
}

void heapIncreaseKey(int A[], int i, int key) {
  if(key < A[i]) {
    // error
    printf("error\n");
  }
  A[i] = key;
  while(i > 1 && A[parent(i)] < A[i]) {
    exchange(A[i], A[parent(i)]);
    i = parent(i);
  }
}

void maxHeapInsert(int A[], int key) {
  ++N;
  A[N] = INT_MIN;
  heapIncreaseKey(A, N, key);
}

int heapExtractMax(int A[]) {
  if(N < 1) {
    printf("heap under flow\n");
  }
  int max = A[1];
  A[1] = A[N];
  N = N-1;
  maxHeapify(A, 1);
  return max;
}


int main() {
  int i;
  char str[128];
  int key;
  N = 0;
  while(scanf("%s", str)) {
    if(str[2] == 's') { // insert
      scanf("%d", &key);
      maxHeapInsert(heap, key);
    } else if(str[2] == 't') { // extract
      printf("%d\n", heapExtractMax(heap));
    } else { // end
      break;
    }
  }
  return 0;
}