import heapq



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

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



X.sort()

dist = [0]*(M-1)



for i in range(M-1):

    dist[i] = -(X[i+1] - X[i])

#print(dist)



heapq.heapify(dist)

for i in range(N-1):

    if len(dist) == 0:

        break

    heapq.heappop(dist)



ans = 0

if len(dist) != 0:

    ans = -sum(dist)

print(ans)

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

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



X.sort()

dist = [0]*(M-1)



for i in range(M-1):

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



dist.sort()

ans = 0

if N < M:

    for i in range((M-1)-(N-1)):

        ans += dist[i]



print(ans)
import heapq

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
dist = [0] * (M - 1)
for i in range(M - 1):
    dist[i] = -(X[i + 1] - X[i])
# print(dist)
heapq.heapify(dist)
for i in range(N - 1):
    if len(dist) == 0:
        break
    heapq.heappop(dist)
ans = 0
if len(dist) != 0:
    ans = -sum(dist)
print(ans)

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
dist = [0] * (M - 1)
for i in range(M - 1):
    dist[i] = X[i + 1] - X[i]
dist.sort()
ans = 0
if N < M:
    for i in range((M - 1) - (N - 1)):
        ans += dist[i]
print(ans)

-import heapq - -    dist[i] = -(X[i + 1] - X[i]) -# print(dist) -heapq.heapify(dist) -for i in range(N - 1): -    if len(dist) == 0: -        break -    heapq.heappop(dist) +    dist[i] = X[i + 1] - X[i] +dist.sort() -if len(dist) != 0: -    ans = -sum(dist) +if N < M: +    for i in range((M - 1) - (N - 1)): +        ans += dist[i]