function maxHeapify(heap, size, id) {
    const left = id * 2;
    const right = id * 2 + 1;
    let largest = id * 2 <= size && heap[left] > heap[id] ? left : id;

    if(id * 2 + 1 <= size && heap[right] > heap[largest]) {
        largest = right;
    }

    if(largest !== id){
        const temp = heap[id];
        heap[id] = heap[largest];
        heap[largest] = temp;
        maxHeapify(heap, size, largest);
    }
}

function insert(heap, key) {
    heap[heap.length] = -Infinity;
    heapIncreaseKey(heap, heap.length, key);
}

function heapIncreaseKey(heap, x, key) {
    if(key < heap[x]){
        return;
    }
    heap[x] = key;
    while(x > 1 && heap[Math.floor(x / 2)] < heap[x]){
        const temp = heap[x];
        heap[x] = heap[Math.floor(x / 2)];
        heap[Math.floor(x / 2)] = temp;
        x = Math.floor(x / 2);
    }
}

function extractMax(heap) {
    if(heap.length < 1){
        return;
    }
    const max = heap[1];
    heap[1] = heap.pop();
    maxHeapify(heap, heap.length, 1);
    return max;
}


function main(_stdin){
    const order = _stdin.split('\n');
    const heap = [null];

    order.forEach((e, i) => {
        const o = e.split(' ');
        if(o[0] === 'insert'){
            insert(heap, parseInt(o[1]));
        } else if(o[0] === 'extract'){
            console.log(extractMax(heap));
        }
    });
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));



