require 'pp'

n, m = gets.chomp!.split(" ").map(&:to_i)
x_m = gets.chomp!.split(" ").map(&:to_i).sort!

#pp x_m

if n >= m
    puts 0
    exit(0)
end

diff = []

x_m.each_cons(2) do |x|
    diff << x[1] - x[0]
end

pp diff.sort[0, (m - 1) - (n - 1)].inject(&:+)
