n, m = gets.split.map(&:to_i)
xi = gets.split.map(&:to_i).sort

if n >= m
    puts 0
    exit
end

d = []
for i in 0..(xi.length-2)
    d << (xi[i] - xi[i+1]).abs
end
d.sort!
puts d[0..(d.length-1-(n-1))].inject(:+)
