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

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

X.sort()



L = [0]*(M-1)

for i in range(M-1):

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

L.sort(reverse=True)



print((X[M-1]-X[0]-sum(L[:N-1])))
def main():

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

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

    X.sort()

    

    h = [0]*M

    for i in range(1, M):

        h[i] = X[i]-X[i-1]

    

    h.sort(reverse=True)

    print((X[M-1]-X[0]-sum(h[:(N-1)])))

main()
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
L = [0] * (M - 1)
for i in range(M - 1):
    L[i] = X[i + 1] - X[i]
L.sort(reverse=True)
print((X[M - 1] - X[0] - sum(L[: N - 1])))

def main():
    N, M = list(map(int, input().split()))
    X = list(map(int, input().split()))
    X.sort()
    h = [0] * M
    for i in range(1, M):
        h[i] = X[i] - X[i - 1]
    h.sort(reverse=True)
    print((X[M - 1] - X[0] - sum(h[: (N - 1)])))


main()

-N, M = list(map(int, input().split())) -X = list(map(int, input().split())) -X.sort() -L = [0] * (M - 1) -for i in range(M - 1): -    L[i] = X[i + 1] - X[i] -L.sort(reverse=True) -print((X[M - 1] - X[0] - sum(L[: N - 1]))) +def main(): +    N, M = list(map(int, input().split())) +    X = list(map(int, input().split())) +    X.sort() +    h = [0] * M +    for i in range(1, M): +        h[i] = X[i] - X[i - 1] +    h.sort(reverse=True) +    print((X[M - 1] - X[0] - sum(h[: (N - 1)]))) + + +main()