n,m=list(map(int,input().split()))

a=list(map(int,input().split()))

a.sort()

ans=[]

if m==1:

    print((0))

    exit()

if n==1:

    print((max(a)-min(a)))

    exit()

for i in range(m-1):

    ans.append(abs(a[i+1]-a[i]))

total=0

ans.sort(reverse=True)

if len(ans)<=n:

    print((0))

    exit()

for i in range(n-1):

    total+=ans[i]

print((sum(ans)-total))

n,m=list(map(int,input().split()))

a=list(map(int,input().split()))

a.sort()

d=[]

for i in range(m-1):

    d.append(a[i+1]-a[i])

d.sort()

total=0

for i in range(m-n):

    total+=d[i]

print(total)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
ans = []
if m == 1:
    print((0))
    exit()
if n == 1:
    print((max(a) - min(a)))
    exit()
for i in range(m - 1):
    ans.append(abs(a[i + 1] - a[i]))
total = 0
ans.sort(reverse=True)
if len(ans) <= n:
    print((0))
    exit()
for i in range(n - 1):
    total += ans[i]
print((sum(ans) - total))

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
d = []
for i in range(m - 1):
    d.append(a[i + 1] - a[i])
d.sort()
total = 0
for i in range(m - n):
    total += d[i]
print(total)

-ans = [] -if m == 1: -    print((0)) -    exit() -if n == 1: -    print((max(a) - min(a))) -    exit() +d = [] -    ans.append(abs(a[i + 1] - a[i])) +    d.append(a[i + 1] - a[i]) +d.sort() -ans.sort(reverse=True) -if len(ans) <= n: -    print((0)) -    exit() -for i in range(n - 1): -    total += ans[i] -print((sum(ans) - total)) +for i in range(m - n): +    total += d[i] +print(total)