n, m = gets.split.map &:to_i
as = gets.split.map &:to_i

#as = []
#100000.times {
# as << (rand * 100000).ceil
#}

as.sort!{|a, b| b <=> a}

cand_i = [[0,0]]
cand = [as[0] + as[0]]

point = 0

m.times{
	i = cand.each_with_index.max[1]
	point += cand[i]
	
	if cand_i[i][0] < n - 1 && cand_i.index([cand_i[i][0] + 1, cand_i[i][1]]) == nil then
		cand_i << [cand_i[i][0] + 1, cand_i[i][1]]
		cand << as[cand_i[i][0] + 1] + as[cand_i[i][1]]
	end
	if cand_i[i][1] < n - 1 && cand_i.index([cand_i[i][0], cand_i[i][1] + 1]) == nil then
		cand_i << [cand_i[i][0], cand_i[i][1] + 1]
		cand << as[cand_i[i][0]] + as[cand_i[i][1] + 1]
	end

	cand_i.delete_at(i)
	cand.delete_at(i)

}

puts point
