$a=[]
$h=0
begin
  command, $key = gets.split
  $key = $key.to_i
  case command
  when 'insert'
    $a[$h]=$key
    i=$h
    while i>0 && $a[i]>$a[pr=(i-1)/2]
      $a[i],$a[pr]=$a[pr],$a[i]
      i=pr
    end
    $h+=1
  when 'extract'
    puts $a[0]
    $h-=1
    $a[0]=$a[$h]
    $a.pop
    i=0
    l=1
    while l < $h
      l+=1 if (r=l+1) < $h && $a[r] > $a[l]
      if $a[i] < $a[l]
        $a[i],$a[l] = $a[l],$a[i]
      end
      i=l
      l=i*2+1
    end
  end
end while command != 'end'