def makelist(n, m):

    return [[0 for _ in range(m)] for _ in range(n)]



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

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



X.sort()

hoge = [0]*(M-1)

for i in range(1, M):

    hoge[i-1] = X[i] - X[i-1]



hoge = list(reversed(sorted(hoge)))



ans = sum(hoge)

if N >= M:

    ans = 0

else:

    for i in range(N-1):

        ans -= hoge[i]

print(ans)

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

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



X = list(sorted(X))

Y = [0]*(M-1)

for i in range(M-1):

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



Y = list(reversed(sorted(Y)))

ans = sum(Y) - sum(Y[:N-1])



print(ans)

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
hoge = [0] * (M - 1)
for i in range(1, M):
    hoge[i - 1] = X[i] - X[i - 1]
hoge = list(reversed(sorted(hoge)))
ans = sum(hoge)
if N >= M:
    ans = 0
else:
    for i in range(N - 1):
        ans -= hoge[i]
print(ans)

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X = list(sorted(X))
Y = [0] * (M - 1)
for i in range(M - 1):
    Y[i] = X[i + 1] - X[i]
Y = list(reversed(sorted(Y)))
ans = sum(Y) - sum(Y[: N - 1])
print(ans)

-def makelist(n, m): -    return [[0 for _ in range(m)] for _ in range(n)] - - -X.sort() -hoge = [0] * (M - 1) -for i in range(1, M): -    hoge[i - 1] = X[i] - X[i - 1] -hoge = list(reversed(sorted(hoge))) -ans = sum(hoge) -if N >= M: -    ans = 0 -else: -    for i in range(N - 1): -        ans -= hoge[i] +X = list(sorted(X)) +Y = [0] * (M - 1) +for i in range(M - 1): +    Y[i] = X[i + 1] - X[i] +Y = list(reversed(sorted(Y))) +ans = sum(Y) - sum(Y[: N - 1])