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

A.sort!.reverse!
a = Array.new(N)
a.map!.with_index{|e, idx| idx}
c = A.map{|a| 2 * a}

ans, m = [0, 0]
while m < M do
  mx = c.max
  idx = c.index(mx)
  ans += mx
  m += 1
  (ans += mx; m+= 1) if m < M && (a[idx] != idx)
  a[idx] += 1
  if a[idx] == N then
    c[idx] = 0
  else
    c[idx] = A[idx] + A[a[idx]]
  end
end

puts ans
