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