#include <stdio.h>
 
#define QSIZE 2000002
 
#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)
 
typedef struct { int t; } QUE;
QUE que[QSIZE+5];
int qsize;
 
void max_heapify(int i)
{
    int l, r, max;
    QUE qt;
    l = LEFT(i), r = RIGHT(i);
    if (l < qsize && que[l].t > que[i].t) max = l; else max = i;
    if (r < qsize && que[r].t > que[max].t) max = r;
    if (max != i) {
        qt = que[i], que[i] = que[max], que[max] = qt;
        max_heapify(max);
    }
}
 
int deq()
{
    int r = que[0].t;
    que[0] = que[--qsize];
    max_heapify(0);
    return r;
}
 
void enq(int t)
{
    int i, max;
    QUE qt;
 
    i = qsize++;
    que[i].t = t;
    while (i > 0 && que[max = PARENT(i)].t < que[i].t) {
        qt = que[i]; que[i] = que[max], que[max] = qt;
        i = max;
    }
}
 
// バッファを経ずstdinから数値を得る
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
char buf[20];
void mypr(int n)
{
    int i = 0;
    if (n == 0) buf[i++] = '0';
    else while (n) buf[i++] = n%10 + '0', n/=10;
    while (i) pc(buf[--i]);
    pc('\n');
}
             
int main()
{
    int k;
 
    qsize = 0;
    while (1) {
        if (gc() == 'e') {
            if (gc() == 'n') break;
            k = 6; while (k--) gc();
            mypr(deq());
        } else {
            k = 6; while (k--) gc();
            enq(in());
        }
    }
    return 0;
}

