a=Array.new(2000000)
s=0
begin
  command, $key = gets.split
  $key = $key.to_i
  case command
  when 'insert'
    a[i=s]=$key
    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]
    a[i=0]=a[s-=1]
    a[s]=nil
    while (l=i*2+1) < s
      if (r=l+1) < s && a[r] > a[l]
        l=r
      end
      if a[i] < a[l]
        a[i],a[l] = a[l],a[i]
      end
      i=l
    end
  end
end while command != 'end'