n, m = gets.strip.split.map { |v| v.to_i }
a = gets.strip.split.map { |v| v.to_i }

combination = []
(0..n-1).each do |i_x|
  (0..i_x-1).each do |i_y|
    2.times do
      combination.push(a[i_x] + a[i_y])
    end
  end
  combination.push(2 * a[i_x])
end

puts combination.sort![n*n-m..n*n-1].inject(&:+)
