# Original solution
import sys


class QueueEmptyError(Exception):
    pass


class PriorityQueue:
    def __init__(self):
        self._nodes = []

    def add(self, v):
        self._nodes.append(v)
        i = len(self._nodes) - 1
        while i > 0:
            parent = (i-1) // 2
            vp, vi = self._nodes[parent], self._nodes[i]
            if vp < vi:
                self._nodes[parent], self._nodes[i] = vi, vp
                i = parent
            else:
                break

    def extract(self):
        size = len(self._nodes) - 1
        if size < 0:
            raise QueueEmptyError()

        node = self._nodes[0]
        last = self._nodes.pop()
        if size > 0:
            self._nodes[0] = last
            i = 0
            while i < size // 2:
                top = i
                left = (i+1) * 2 - 1
                right = (i+1) * 2
                vi = self._nodes[top]
                vt = vi
                if left < size:
                    vl = self._nodes[left]
                    if vl > vt:
                        top = left
                        vt = vl
                if right < size:
                    vr = self._nodes[right]
                    if vr > vt:
                        top = right
                        vt = vr

                if top > i:
                    self._nodes[top], self._nodes[i] = vi, vt
                    i = top
                else:
                    break

        return node


def run():
    q = PriorityQueue()

    for line in sys.stdin:
        if line.startswith("i"):
            q.add(int(line[7:]))
        elif line.startswith("ex"):
            print((q.extract()))
        elif line.startswith("end"):
            break
        else:
            ValueError("invalid command")


if __name__ == '__main__':
    run()



# Optimized solution
import sys


def run():
    q = []

    for line in sys.stdin:
        if line.startswith("i"):
            v = int(line[7:])
            q.append(v)
            i = len(q) - 1
            while i > 0:
                p = (i-1) // 2
                vp = q[p]
                if vp < v:
                    q[p], q[i] = v, vp
                    i = p
                else:
                    break
        elif line.startswith("ex"):

            size = len(q) - 1
            if size < 0:
                raise ValueError('get from empty queue')

            v = q[0]
            last = q.pop()
            if size > 0:
                q[0] = last
                i = 0
                while i < size // 2:
                    top, vt = i, last
                    left = (i+1) * 2 - 1
                    right = (i+1) * 2
                    if left < size:
                        vl = q[left]
                        if vl > vt:
                            top, vt = left, vl
                    if right < size:
                        vr = q[right]
                        if vr > vt:
                            top, vt = right, vr

                    if top > i:
                        q[top], q[i] = last, vt
                        i = top
                    else:
                        break
            print(v)
        elif line.startswith("end"):
            break
        else:
            ValueError("invalid command")


if __name__ == '__main__':
    run()