import sys

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

if N >= M:

    print((0))

    sys.exit()

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

X.sort()

D = []

D = [X[i+1] - X[i] for i in range(M-1)]

D.sort(reverse = True)

ans = 0

for i in range(N-1):

    ans -= D[i]

ans += X[-1] - X[0]

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

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

X.sort()

L = []



for i in range(M-1):

    L.append(X[i+1] - X[i])



L.sort()



if M - N <= 0:

    print((0))

else:

    print((sum(L[:M - N])))
import sys

N, M = list(map(int, input().split()))
if N >= M:
    print((0))
    sys.exit()
X = list(map(int, input().split()))
X.sort()
D = []
D = [X[i + 1] - X[i] for i in range(M - 1)]
D.sort(reverse=True)
ans = 0
for i in range(N - 1):
    ans -= D[i]
ans += X[-1] - X[0]
print(ans)

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

-import sys - -if N >= M: -    print((0)) -    sys.exit() -D = [] -D = [X[i + 1] - X[i] for i in range(M - 1)] -D.sort(reverse=True) -ans = 0 -for i in range(N - 1): -    ans -= D[i] -ans += X[-1] - X[0] -print(ans) +L = [] +for i in range(M - 1): +    L.append(X[i + 1] - X[i]) +L.sort() +if M - N <= 0: +    print((0)) +else: +    print((sum(L[: M - N])))