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

struct node{
  int key;
  struct node *next;
};
struct node *head;

void insert(int k){
  struct node *x;
  struct node *y;
  x = (struct node *)malloc(sizeof(struct node));
  x->key = k;
  x->next = NULL;
  if(head == NULL){
    head = x;
    return;
  }

  if(head->key < x->key){
    x->next = head;
    head = x;
    return;
  }
  
  if(head->next == NULL){
    head->next = x;
    return;
  }

  y = head->next;
  struct node *p;
  p = head;
  while(y != NULL){
    if(y->key < x->key){
      p->next = x;
      x->next = y;
      return;
    }else{
      if(y->next == NULL){
	y->next = x;
	return;
      }
      p = y;
      y = y->next;
    }
  }
}

void extract(void){
  printf("%d\n", head->key);
  head = head->next;
}

int main(void){
  int i, x;
  char s[16];
  head = (struct node *)malloc(sizeof(struct node));
  head = NULL;
  
  while(1){
    scanf("%s", s);
    if(!strcmp(s, "insert")){
      scanf("%d", &x);
      insert(x);
    }else if(!strcmp(s, "extract")){
      extract();
    }else if(!strcmp(s, "end")){
      break;
    }
    /*struct node *x;
    x = head;
    while(x != NULL){
      printf("%d ", x->key);
      x = x->next;
    }
    printf("\n");
    */
  }
  return 0;
}
