def maxHeapify i
  l = i*2
  r = l+1
  max = l<=$h && $a[l-1] > $a[i-1] ? l : i
  max = r if r <= $h && $a[r-1] > $a[max-1]
  unless max == i
    $a[i-1],$a[max-1] = $a[max-1],$a[i-1]
    maxHeapify max
  end
end
def insert
  $a<<$key
  $h=$a.size
  ($h/2).downto(1) {|i| maxHeapify i}
end
$a=[]
begin
  command, $key = gets.split
  $key = $key.to_i
  case command
  when 'insert'
    insert
  when 'extract'
    puts $a.shift
    $h-=1
    ($h/2).downto(1) {|i| maxHeapify i}
  end
end while command != 'end'