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

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

if N >= M:

    print((0))

else:

    X.sort()

    gap = []

    for i in range(1,M):

        gap.append(X[i]-X[i-1])

    s = X[M-1] - X[0]

    gap.sort(reverse=True)

    d = 0

    for i in range(N-1):

        d += gap[i]

    print((s-d))
N,M = list(map(int,(input().split())))

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

if N >= M:

    print((0))

else:

    X.sort()

    gap = []

    for i in range(1,M):

        gap.append(X[i]-X[i-1])

    s = X[M-1] - X[0]

    gap.sort(reverse=True)

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

N, M = list(map(int, (input().split())))
X = list(map(int, (input().split())))
if N >= M:
    print((0))
else:
    X.sort()
    gap = []
    for i in range(1, M):
        gap.append(X[i] - X[i - 1])
    s = X[M - 1] - X[0]
    gap.sort(reverse=True)
    print((s - sum(gap[0 : N - 1])))

-    d = 0 -    for i in range(N - 1): -        d += gap[i] -    print((s - d)) +    print((s - sum(gap[0 : N - 1])))