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