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

y=(0..m-2).map{|i|[x[i+1]-x[i],i]}

z=y.sort{|s,t|t[0]<=>s[0]}[0..n-1].sort{|s,t|s[1]<=>t[1]}

z.unshift([0,0])
z.push([0,m-1])


cnt=0
start=0


while z.size!=0
    mae=z.shift[1]
    if z.size==0
        usiro=m-1
    else 
        usiro=z.shift[1]
    end
    cnt+=x[usiro]-x[mae]
end

p cnt