def maxHeapify a,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 a,max
  end
end
def makeMaxHeap a
  ($h/2).downto(1) {|i| maxHeapify a,i}
end
a=[]
$h=0
min=0
begin
  command, $key = gets.split
  $key = $key.to_i
  case command
  when 'insert'
    a[$h]=$key
    $h+=1
    makeMaxHeap a
  when 'extract'
    puts a[0]
    $h-=1
    a[0]=a[$h]
    makeMaxHeap a
  end
end while command != 'end'