n,m=gets.split.map &:to_i
n=m if n>m
s=gets.split.map &:to_i
s.sort!
sa=[]
for i in 0..m-2
  sa << s[i+1]-s[i]
end
kai=sa.zip((0..m-1).to_a).sort_by{|i|[-i[0],i[1]]}
sum=0
wa=0
for i in 0..n-2
  sum+=s[kai[i][1]]-s[wa]
  wa=kai[i][1]+1
end
sum+=s[m-1]-s[wa]
puts sum
