n, m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i).sort
if m < n
    puts 0
else
    s = x.size
    diff = Array.new
    0.upto(s - 2) do |i|
        diff[i] = x[i + 1] - x[i]
    end
    diff.sort!
    puts diff[0..-n].inject(:+)
end
