from heapq import heappush, heappop





N, M = list(map(int, input().split()))

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



X.sort()



if N >= M:

    print((0))

    exit()



q1 = []



for i in range(M - 1):

    sec = X[i + 1] - X[i]

    heappush(q1, (-sec, i + 1))



q2 = []

for n in range(N - 1):

    sec, idx = heappop(q1)

    heappush(q2, idx)



heappush(q2, M)

cur = 0

ans = 0

for n in range(N):

    idx = heappop(q2)

    ans += X[idx - 1] - X[cur]

    cur = idx



print(ans)

from heapq import heappush, heappop





N, M = list(map(int, input().split()))

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



X.sort()



if N >= M:

    print((0))

    exit()



q1 = []



for i in range(M - 1):

    sec = X[i + 1] - X[i]

    heappush(q1, -sec)



ans = 0

for _ in range(N - 1):

    ans -= heappop(q1)



print((X[-1] - X[0] - ans))

from heapq import heappush, heappop

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
if N >= M:
    print((0))
    exit()
q1 = []
for i in range(M - 1):
    sec = X[i + 1] - X[i]
    heappush(q1, (-sec, i + 1))
q2 = []
for n in range(N - 1):
    sec, idx = heappop(q1)
    heappush(q2, idx)
heappush(q2, M)
cur = 0
ans = 0
for n in range(N):
    idx = heappop(q2)
    ans += X[idx - 1] - X[cur]
    cur = idx
print(ans)

from heapq import heappush, heappop

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
if N >= M:
    print((0))
    exit()
q1 = []
for i in range(M - 1):
    sec = X[i + 1] - X[i]
    heappush(q1, -sec)
ans = 0
for _ in range(N - 1):
    ans -= heappop(q1)
print((X[-1] - X[0] - ans))

-    heappush(q1, (-sec, i + 1)) -q2 = [] -for n in range(N - 1): -    sec, idx = heappop(q1) -    heappush(q2, idx) -heappush(q2, M) -cur = 0 +    heappush(q1, -sec) -for n in range(N): -    idx = heappop(q2) -    ans += X[idx - 1] - X[cur] -    cur = idx -print(ans) +for _ in range(N - 1): +    ans -= heappop(q1) +print((X[-1] - X[0] - ans))