a = gets.split(" ").map{|item|item.to_i}
b = gets.split(" ").map{|item|item.to_i}.sort.reverse
l = []
(a[1]-1).times{|k|
l.push(b[k]-b[k+1])
}
l = l.sort.reverse

print b[0] - b[-1] - l[0..(a[0]-2)].inject(:+)