require 'pp'

n, m = gets.split.map(&:to_i)
a_n = gets.split.map(&:to_i).sort!.reverse!

head = 0
tail = 0

sum = 0
i = 0
before = 0

#pp a_n

while i < m
    s = a_n[head] + a_n[tail]
    sum += s
    i += 1
    break if i >= m

    #pp s

    if head != tail
        #pp s
        sum += s
        i += 1
        break if i >= m
    end

    if tail == n - 1
        head += 1
        tail = head
    else
        tail += 1
    end
end

puts sum
