#include<stdio.h>
#include<stdlib.h>
#define MAX (2000000 + 1)
typedef struct node{
  int key;
  struct node *p, *l, *r;
}T_node;
T_node **heap;
int n;
void mahpy(T_node ** ,int);
void insert(int);
int extract();
int main(){
  char buf[256];
  int v;
  n = 0;
  heap = (T_node **)malloc(sizeof(T_node *) * MAX);
  int i;
  for(i = MAX; i > MAX / 2; i--){
    heap[i] = (T_node *)malloc(sizeof(T_node));
    heap[i]->key = -1;
    heap[i]->p = heap[i]->l = heap[i]->r = NULL;
  }
  for(i = MAX / 2; i > 0; i--){
    heap[i] = (T_node *)malloc(sizeof(T_node));
    heap[i]->key = -1;
    heap[i]->l = heap[i * 2];
    heap[i]->r = heap[i * 2 + 1];
    heap[i * 2]->p = heap[i * 2 + 1]->p = heap[i];
  }
  heap[1]->p = NULL;
  while(scanf("%s", buf) & strcmp(buf, "end")){
    if(!strcmp(buf, "insert")){
      n++;
      scanf("%d", &v);
      insert(v);
    }
    else if(!strcmp(buf, "extract")){
      printf("%d\n", extract());
      n--;
    }
  }
  for(i = MAX; i > 0; i--)
    free(heap[i]);
  free(heap);
  return 0;
}

void insert(int v){
  heap[n]->key = v;
/*  if(n /2){
    heap[n]->p = heap[n / 2];
    if(n % 2)
      heap[n / 2]->r = heap[n];
    else
      heap[n / 2]->l = heap[n];
  }*/
  T_node *ma;
/*  for(ma = heap[n]; ma->p != NULL; ma = ma->p){
    if(ma->key > ma->p->key){
      ma->key = ma->p->key;
      ma->p->key = v;
    }
    else
      break;
  }*/
  int i;
  for(i = n / 2; i > 0; i--)
    mahpy(heap, i);
}

int extract(){
  int tmp = heap[1]->key;
  heap[1]->key = -1;
  int i;
  for(i = n / 2; i > 0; i--)
    mahpy(heap, i);
  return tmp;
}

void mahpy(T_node **heap, int i){
  T_node *max;
  int tmp, ni = 0;
  if(heap[i]->r != NULL){
    if(heap[i]->l->key >= heap[i]->r->key){
      max = heap[i]->l;
      if(max->key >= 0)
	ni = i * 2;
    }
    else{
      max = heap[i]->r;
      if(max->key >= 0)
	ni = i * 2 + 1;
    }
  }
  else if(heap[i]->l != NULL){
    max = heap[i]->l;
    if(max->key >= 0)
      ni = i * 2;
  }
  else
    max = heap[i];
  if(max->key > heap[i]->key){
    tmp = heap[i]->key;
    heap[i]->key = max->key;
    max->key = tmp;
  }
  if(ni)
    mahpy(heap, ni);
  else if(heap[i]->key == -1){
    heap[i]->key = heap[n]->key;
    heap[n]->key = -1;
/*    heap[n]->p = heap[n]->l = heap[i]->r = NULL;
    if(n % 2)
      heap[n / 2]->r = NULL;
    else
      heap[n / 2]->l = NULL;*/
  }
}