import sys

import heapq

inf = 10**6

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



if n >= m:

  print((0))

  sys.exit()



a = [int(x) for x in input().split()]

a.sort()



count = []

heapq.heapify(count)

for i in range(m-1):

  heapq.heappush(count, -a[i+1]+a[i])



ans = 0

for j in range(n-1):

  ans -= heapq.heappop(count)

ans = max(a)-min(a)-ans

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

a = [int(x) for x in input().split()]

a.sort()

b = [a[i+1]-a[i] for i in range(n-1)]

b.sort(reverse=True)



print((a[-1]-a[0]-sum(b[:min([m-1, n-1])])))
import sys
import heapq

inf = 10**6
n, m = list(map(int, input().split()))
if n >= m:
    print((0))
    sys.exit()
a = [int(x) for x in input().split()]
a.sort()
count = []
heapq.heapify(count)
for i in range(m - 1):
    heapq.heappush(count, -a[i + 1] + a[i])
ans = 0
for j in range(n - 1):
    ans -= heapq.heappop(count)
ans = max(a) - min(a) - ans
print(ans)

m, n = list(map(int, input().split()))
a = [int(x) for x in input().split()]
a.sort()
b = [a[i + 1] - a[i] for i in range(n - 1)]
b.sort(reverse=True)
print((a[-1] - a[0] - sum(b[: min([m - 1, n - 1])])))

-import sys -import heapq - -inf = 10**6 -n, m = list(map(int, input().split())) -if n >= m: -    print((0)) -    sys.exit() +m, n = list(map(int, input().split())) -count = [] -heapq.heapify(count) -for i in range(m - 1): -    heapq.heappush(count, -a[i + 1] + a[i]) -ans = 0 -for j in range(n - 1): -    ans -= heapq.heappop(count) -ans = max(a) - min(a) - ans -print(ans) +b = [a[i + 1] - a[i] for i in range(n - 1)] +b.sort(reverse=True) +print((a[-1] - a[0] - sum(b[: min([m - 1, n - 1])])))