import numpy as np



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

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

X_sort = np.array(sorted(X))[::-1]

X_diff = X_sort[:M-1] - X_sort[1:]



X_diff_sort = sorted(X_diff)[::-1]



print((max(sum(X_diff_sort[N-1:]), 0)))
import numpy as np



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

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

X = np.array(X)



X_sorted = np.sort(X)[::-1]

X_diff = X_sorted[:-1] - X_sorted[1:]

X_diff_sorted = np.sort(X_diff)[::-1]



print((X_sorted[0] - X_sorted[-1] - X_diff_sorted[:N-1].sum()))
import numpy as np

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X_sort = np.array(sorted(X))[::-1]
X_diff = X_sort[: M - 1] - X_sort[1:]
X_diff_sort = sorted(X_diff)[::-1]
print((max(sum(X_diff_sort[N - 1 :]), 0)))

import numpy as np

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X = np.array(X)
X_sorted = np.sort(X)[::-1]
X_diff = X_sorted[:-1] - X_sorted[1:]
X_diff_sorted = np.sort(X_diff)[::-1]
print((X_sorted[0] - X_sorted[-1] - X_diff_sorted[: N - 1].sum()))

-X_sort = np.array(sorted(X))[::-1] -X_diff = X_sort[: M - 1] - X_sort[1:] -X_diff_sort = sorted(X_diff)[::-1] -print((max(sum(X_diff_sort[N - 1 :]), 0))) +X = np.array(X) +X_sorted = np.sort(X)[::-1] +X_diff = X_sorted[:-1] - X_sorted[1:] +X_diff_sorted = np.sort(X_diff)[::-1] +print((X_sorted[0] - X_sorted[-1] - X_diff_sorted[: N - 1].sum()))