import numpy as np



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

X = np.array(sorted(map(int, input().split())))



distances = sorted(X[1:] - X[:-1], reverse=True)

print((sum(distances[N-1:])))
# coding: utf-8

import sys

import numpy as np



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M = lr()

X = np.array(lr())

X.sort()

if N >= M:

    print((0)); exit()



Xdiff = np.abs(np.diff(X))

Xdiff.sort()

need = M - N

answer = Xdiff[:need].sum()

print(answer)

import numpy as np

N, M = list(map(int, input().split()))
X = np.array(sorted(map(int, input().split())))
distances = sorted(X[1:] - X[:-1], reverse=True)
print((sum(distances[N - 1 :])))

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
X = np.array(lr())
X.sort()
if N >= M:
    print((0))
    exit()
Xdiff = np.abs(np.diff(X))
Xdiff.sort()
need = M - N
answer = Xdiff[:need].sum()
print(answer)

+# coding: utf-8 +import sys -N, M = list(map(int, input().split())) -X = np.array(sorted(map(int, input().split()))) -distances = sorted(X[1:] - X[:-1], reverse=True) -print((sum(distances[N - 1 :]))) +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N, M = lr() +X = np.array(lr()) +X.sort() +if N >= M: +    print((0)) +    exit() +Xdiff = np.abs(np.diff(X)) +Xdiff.sort() +need = M - N +answer = Xdiff[:need].sum() +print(answer)