import sys



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

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



if N>=M:

    print((0))

    sys.exit()



X.sort()



Y=[0]*(M-1)

for i in range(M-1):

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



Y=sorted(Y)[:-(N-M)]

print((sum(Y)))
import sys



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

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



X.sort()



Y=[0]*(M-1)

for i in range(M-1):

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



Y=sorted(Y)[:max(0,M-N)]

print((sum(Y)))
import sys

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

import sys

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

-if N >= M: -    print((0)) -    sys.exit() -Y = sorted(Y)[: -(N - M)] +Y = sorted(Y)[: max(0, M - N)]