a = gets.split(" ").map{|item|item.to_i}
if a[0] >= a[1] then
    print 0
    exit
end


b = gets.split(" ").map{|item|item.to_i}.sort

if a[0] == 1 then
    print b[-1] - b[0]
    exit
end

    


l = []
(a[1]-1).times{|k|
l.push(b[k+1]-b[k])
}
l = l.sort.reverse

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