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

#define M 2000000
#define INF 1000

#define parent(x) (x/2)
#define left(x) (x*2)
#define right(x) (x*2+1)

void insert(int *,int);
int extract(int *);
void heapIncreaseKey(int *,int,int);
void maxHeapify(int *,int);

int size;

int main(){
  int buf;
  int i;
  int A[M];
  char c[10];
  
  
  while(1){
    scanf("%s",c);
    if(strcmp(c,"end")==0) break;
    if(strcmp(c,"insert")==0){
      scanf("%d",&buf);
      insert(A,buf);
    }else printf("%d\n",extract(A));
  }
  
  return 0;
}

void insert(int *A,int buf){
  size=size+1;
  A[size]=-INF;
  heapIncreaseKey(A,size,buf);
}

void heapIncreaseKey(int *A,int i,int buf){
  int temp;
  
  if(buf<A[i]) fprintf(stderr,"new key is smaller than current key\n");
  A[i]=buf;
  while(i>1 && A[parent(i)]<A[i]){
    temp=A[i];
    A[i]=A[parent(i)];
    A[parent(i)]=temp;
    
    i=parent(i);
  }
}

int extract(int *A){
  int max;
  if(size < 1) fprintf(stderr,"heap underflow\n");
  max=A[1];
  A[1]=A[size];
  size--;
  maxHeapify(A,1);
  return max;
}

void maxHeapify(int *A,int i){
  int l,r,large,temp;

  l=left(i);
  r=right(i);

  if(l<=size && A[l]>A[i]) large=l;
  else large=i;
  if(r<=size && A[r] > A[large]) large=r;
  if(large!=i){
    temp=A[i];
    A[i]=A[large];
    A[large]=temp;
    maxHeapify(A,large);
  }
}

