import scala.io.StdIn.readLine;
import scala.reflect.ClassTag;
object Main {
    def main(args: Array[String]): Unit = {
        val pq = new PriorityQueue[Int]();
        def go(ret: List[Int]): List[Int] = {
            val line = readLine;
            if (line.startsWith("insert")) {
                val Array(command, id) = line.split(" ");
                pq.insert(id.toInt);
                go(ret);
            } else if (line.startsWith("extract")) {
                pq.extract match {
                    case None => go(ret);
                    case Some(id) => go(id :: ret);
                }
            } else {
                ret.reverse;
            }
        }
        println(go(Nil).mkString("\n"))
    }
    
}
class PriorityQueue[A](implicit ord: Ordering[A], m: ClassTag[A]) {
    import ord._;
    val heap = m.newArray(2000000);
    var length = 0;
    def insert(id: A): Unit = {
        heap(length) = id;
        length += 1;
        build;
    }
    
    def extract: Option[A] = {
        if (length < 1) {
            None
        } else if (length == 1) {
            length -=1;
            Some(heap(0));
        } else {
            val ret = Some(heap(0));
            length -= 1;
            heap(0) = heap(length);
            heapify(0);
            ret;
        }
    }
    def build: Unit = {
        def go(idx: Int): Unit = {
            if (idx < length) {
                go(idx * 2 + 1);
                go(idx * 2 + 2);
                heapify(idx);
            }
        }
        go(0);
    }
    def heapify(idx: Int): Unit = {
        val left = idx * 2 + 1;
        val right = idx * 2 + 2;
        if (right < length) {
            val m = max(idx, left, right);
            if (idx != m) {
                swap(idx, m);
                heapify(m);
            }
        } else if (left < length) {
            if (heap(left) > heap(idx)){
                swap(idx, left);
            }
        }
    }
    def max(k1: Int, k2: Int, k3: Int): Int = {
        val v1 = heap(k1); val v2 = heap(k2); val v3 = heap(k3);
        if (v2 > v1) {
            if (v3 > v2) k3 else k2;
        } else {
            if (v3 > v1) k3 else k1;
        }
    }
    def swap(a: Int, b: Int): Unit = {
        val tmp = heap(a);
        heap(a) = heap(b);
        heap(b) = tmp;
    }
}

