import scala.io.StdIn.readLine

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

  def extract() = {
    val h = i-1
    q(0) = q(h)
    q(h) = 0

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

    down(0)
    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() }
      }
    }
  }
}