n, m, *a = $stdin.read.split.map(&:to_i)
a.sort!.unshift(-99999999)

q = [[a[n] * 2, n, n]]
sum = 0

m.times do
  h, x, y = q.pop
  sum += h
  
  q << [a[x - 1] + a[y], x - 1, y] << [a[x] + a[y - 1], x, y - 1]
  q.sort!.uniq! { |h, x, y| [x, y] }
end

puts sum
