import sys

n,m = list(map(int, input().split()))

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



if n >= m:

    print((0))

    sys.exit(0)



X.sort()

Y = []

for i in range(len(X)-1):

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

Y.sort(reverse=True)



print((X[-1]-X[0]-sum(Y[:n-1])))

import sys

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

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



if N >= M:

  print((0))

  sys.exit()



X.sort() # O(MlogM)



# O(M)

D = []

for i in range(M-1):

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



D.sort() # O(MlogM)



print((sum(D[:M-N]))) # O(M)

import sys

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

import sys

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

-n, m = list(map(int, input().split())) +N, M = list(map(int, input().split())) -if n >= m: +if N >= M: -    sys.exit(0) -X.sort() -Y = [] -for i in range(len(X) - 1): -    Y.append(X[i + 1] - X[i]) -Y.sort(reverse=True) -print((X[-1] - X[0] - sum(Y[: n - 1]))) +    sys.exit() +X.sort()  # O(MlogM) +# O(M) +D = [] +for i in range(M - 1): +    D.append(X[i + 1] - X[i]) +D.sort()  # O(MlogM) +print((sum(D[: M - N])))  # O(M)