#include <stdio.h>
#define M 2000000
#define CENTER(i) ((i)>>1)
#define WHITE(i)  ((i)<<1)
#define BLACK(i)  (((i)<<1)+1)

typedef struct{
  int k;
}WAG;

int cc;
WAG c[M+5];

void extract(int i){
  int w,b,ex;
  WAG rt;
  w = WHITE(i),b = BLACK(i);
  if(w < cc && c[w].k > c[i].k){
    ex = w;
  }
  else{
    ex = i;
  }
  if(b < cc && c[b].k > c[ex].k){
    ex = b;
  }
  if(ex != i){
    rt = c[i],c[i] = c[ex],c[ex] = rt;
    extract(ex);
  }
}

int rise(){
  int g = c[0].k;
  c[0] = c[--cc];
  extract(0);
  return g;
}

void delm(int k){
  int i,ex;
  WAG rt;

  i = cc++;
  c[i].k = k;
  while(i>0&&c[ex=CENTER(i)].k < c[i].k){
    rt = c[i];
    c[i] = c[ex];
    c[ex] = rt;
    i = ex;
  }
}

#if 1
#define gun() getchar_unlocked()
#define pun(c) putchar_unlocked(c)
#else 
#define gun() getchar()
#define pun(c) putchar(c)
#endif

int gp(){
  int m = 0;
  int c = gun();
  do m = 10 * m + (c & 0xf), c = gun(); while(c >= '0');
  return m;
}

char a[20];
void bump(int m){
  int i = 0;
  if(m==0)
    a[i++] = '0';  
  else
    while(m)
      a[i++] = m % 10 + '0',m/=10;
  while(i)
    pun(a[--i]);
    pun('\n');
}

int main(){
  int l;

  cc = 0;

  while(1){
    if(gun()=='e'){
      if(gun()=='n')
	break;
      l = 6;
      while(l--)
	gun();
      bump(rise());
    }
    else{
      l=6;
      while(l--)
	gun();
      delm(gp());   
    }
  }
  return 0;
}

