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

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

ans = 0

if M>N:

  X.sort()

  D = []

  for i in range(M-1):

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

    D.append(d)

  

  D.sort()

  D = D[:(M-N)]

  ans = sum(D)

  

print(ans)

  

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

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

X.sort()

A = []

for i in range(1, M):

    L = X[i] - X[i - 1]

    A.append(L)

A.sort()

A = A[M - N:]

ans = X[-1] - X[0] - sum(A)

if N >= M:

    ans = 0

print(ans)

  

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

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
A = []
for i in range(1, M):
    L = X[i] - X[i - 1]
    A.append(L)
A.sort()
A = A[M - N :]
ans = X[-1] - X[0] - sum(A)
if N >= M:
    ans = 0
print(ans)

-ans = 0 -if M > N: -    X.sort() -    D = [] -    for i in range(M - 1): -        d = X[i + 1] - X[i] -        D.append(d) -    D.sort() -    D = D[: (M - N)] -    ans = sum(D) +X.sort() +A = [] +for i in range(1, M): +    L = X[i] - X[i - 1] +    A.append(L) +A.sort() +A = A[M - N :] +ans = X[-1] - X[0] - sum(A) +if N >= M: +    ans = 0