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

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



X.sort()

diff = [0]*(M-1)

for i in range(M-1):

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



diff.sort()

if N>=M:

    ans = 0

else:

    ans = sum(diff[:M-N])

print(ans)
def solve():

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

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

  X.sort()

  lis = []

  for i in range(M-1):

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

  lis.sort(reverse=True)

  ans = X[-1]-X[0]-sum(lis[:N-1])

  return ans

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

def solve():
    N, M = list(map(int, input().split()))
    X = list(map(int, input().split()))
    X.sort()
    lis = []
    for i in range(M - 1):
        lis.append(X[i + 1] - X[i])
    lis.sort(reverse=True)
    ans = X[-1] - X[0] - sum(lis[: N - 1])
    return ans


print((solve()))

-N, M = list(map(int, input().split())) -X = list(map(int, input().split())) -X.sort() -diff = [0] * (M - 1) -for i in range(M - 1): -    diff[i] = X[i + 1] - X[i] -diff.sort() -if N >= M: -    ans = 0 -else: -    ans = sum(diff[: M - N]) -print(ans) +def solve(): +    N, M = list(map(int, input().split())) +    X = list(map(int, input().split())) +    X.sort() +    lis = [] +    for i in range(M - 1): +        lis.append(X[i + 1] - X[i]) +    lis.sort(reverse=True) +    ans = X[-1] - X[0] - sum(lis[: N - 1]) +    return ans + + +print((solve()))