n,m=io.read("*n","*n","*l")
if n>=m then
    print(0)
    return
end

x={}
for i=1,m do
    x[i]=io.read("*n")
end
table.sort(x)

l={}
for i=1,m-1 do
    table.insert(l,x[i+1]-x[i])
end
table.sort(l)

distance=0
for i=1,m-n do
    distance=distance+l[i]
end
print(distance)