def pq()
  q = []
  a = []
  loop{
    a = gets.split(' ')
    if a[0] == 'insert'
      n = a[1].to_i
      q.push(n)
      i = q.length-1
      until i == 0
        if q[i] > q[i/2]
          r = q[i]
          q[i] = q[i/2]
          q[i/2] = r          
        else
          break
        end
      end
    elsif a[0] == 'extract'
      n = q.shift
      puts n
    elsif a[0] == 'end'
      break
    end
  }
end

pq()