N, M = gets.chomp.split(" ").map{|s| s.to_i}
A_ARR = gets.chomp.split(" ").map{|s| s.to_i}

arr = []
A_ARR.each do |n|
  A_ARR.each do |m|
    arr << [n, m]
  end
end

sarr = arr.sort_by{|n, m| -1 * (n + m)}

happiness = 0
M.times do |i|
  n, m = sarr[i]
  happiness += n + m
end

puts happiness
