import sys



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

if N >= M:

    print((0))

    sys.exit(0)



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

X.sort()



distance_list = []

for i in range(M-1):

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



distance_list.sort(reverse=True)

print((X[-1] - X[0] - sum(distance_list[:N-1])))

import sys



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

if N >= M:

    print((0))

    sys.exit(0)



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

X.sort()



distance_list = [b - a for a, b in zip(X,X[1:])]

distance_list.sort()



print((sum(distance_list[:M-N])))

import sys

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

import sys

N, M = list(map(int, input().split()))
if N >= M:
    print((0))
    sys.exit(0)
X = list(map(int, input().split()))
X.sort()
distance_list = [b - a for a, b in zip(X, X[1:])]
distance_list.sort()
print((sum(distance_list[: M - N])))

-distance_list = [] -for i in range(M - 1): -    distance_list.append(X[i + 1] - X[i]) -distance_list.sort(reverse=True) -print((X[-1] - X[0] - sum(distance_list[: N - 1]))) +distance_list = [b - a for a, b in zip(X, X[1:])] +distance_list.sort() +print((sum(distance_list[: M - N])))