import scala.io.StdIn.readLine

object Main {
  val q = new Array[Int](2000000)
  var i = 0

  def extract() = {
    q(0) = q(i)

    def down(j:Int):Unit = {
      var largest = j
      if(2*j <= i) {
        if(q(j*2-1) > q(j-1)) largest = j*2
        if(j*2+1<= i && q(j*2) > q(largest-1)) largest = j*2+1
        if(largest!=j) {
          val temp = q(largest-1)
          q(largest-1) = q(j-1)
          q(j-1) = temp
          down(largest)
        }
      }
    }

    down(1)
    i -= 1
  }

  def insert(n:Int) = {
    q(i) = n
    def up(j:Int):Unit =
      if(j>0 && q(j/2) < q(j)) {
        val temp = q(j/2)
        q(j/2) = q(j)
        q(j) = temp
        up(j/2)
      }
    up(i)
    i+=1
  }

  def main(args:Array[String]) = {
    Iterator.continually(readLine).takeWhile(_.trim != "end").foreach { s=>
      val m = s.split(" ")
      m(0) match {
        case "insert" => insert(m(1).toInt)
        case "extract" => { println(q(0)); extract() }
      }
    }
  }
}