import numpy as np



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

X = [int(i) for i in input().split()]



# 昇順

X.sort()



# numpy array 配列の差分

D = np.diff(X)



# numpy array 降順

D = np.sort(D)[::-1]



# numpy array 先頭から N - 2 まで 合計

print((X[-1] - X[0] - np.sum(D[:N - 1])))

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

X = [int(i) for i in input().split()]



X.sort()



D = [X[i+1] - X[i] for i in range(M - 1)]



D.sort()



print((0 if M <= N else sum(D[:M-N])))

import numpy as np

N, M = list(map(int, input().split()))
X = [int(i) for i in input().split()]
# 昇順
X.sort()
# numpy array 配列の差分
D = np.diff(X)
# numpy array 降順
D = np.sort(D)[::-1]
# numpy array 先頭から N - 2 まで 合計
print((X[-1] - X[0] - np.sum(D[: N - 1])))

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

-import numpy as np - -# 昇順 -# numpy array 配列の差分 -D = np.diff(X) -# numpy array 降順 -D = np.sort(D)[::-1] -# numpy array 先頭から N - 2 まで 合計 -print((X[-1] - X[0] - np.sum(D[: N - 1]))) +D = [X[i + 1] - X[i] for i in range(M - 1)] +D.sort() +print((0 if M <= N else sum(D[: M - N])))