#二分ヒープ
class BinaryHeap
  def initialize(a, &b)
    @heap = a
    @size = a.size
    #ex) |parent, child| parent <= child
    @b = b
  end
  def change
    me = 0
    x = @heap[0] / 2
    while me < @size do
      child = (me << 1) + 1
      break if child >= @size
      if (child + 1) < @size && @b.call(@heap[child + 1], @heap[child]) then
        child += 1
      end
      break if @b.call(x, @heap[child])
      @heap[me] = @heap[child]
      me = child
    end
    @heap[me] = x
  end
  def inject
    @heap.inject(&:+)
  end
end

N, M = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

A.sort!.reverse!
bh = BinaryHeap.new(A){|parent, child| parent >= child}
M.times{ bh.change}

puts bh.inject
