N, M = input().split()

N = int(N)

M = int(M)

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



X = sorted(X)

L = []

for i in range(1,M):

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



L = sorted(L)

if N >= M:

    print((0))

elif N == 1:

    print((sum(L)))

else:

    print((sum(L[:-N+1])))
def main():

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

    x = sorted(list(map(int, input().split())))



    sa = []

    for i in range(M-1):

        sa.append(x[i+1] - x[i])

    sa = sorted(sa, reverse=True)

    # print(sa)

    if N >= M:

        print((0))

    else:

        print((sum(sa[N-1:])))





if __name__ == "__main__":

    main()
N, M = input().split()
N = int(N)
M = int(M)
X = list(map(int, input().split(" ")))
X = sorted(X)
L = []
for i in range(1, M):
    L.append(X[i] - X[i - 1])
L = sorted(L)
if N >= M:
    print((0))
elif N == 1:
    print((sum(L)))
else:
    print((sum(L[: -N + 1])))

def main():
    N, M = list(map(int, input().split()))
    x = sorted(list(map(int, input().split())))
    sa = []
    for i in range(M - 1):
        sa.append(x[i + 1] - x[i])
    sa = sorted(sa, reverse=True)
    # print(sa)
    if N >= M:
        print((0))
    else:
        print((sum(sa[N - 1 :])))


if __name__ == "__main__":
    main()

-N, M = input().split() -N = int(N) -M = int(M) -X = list(map(int, input().split(" "))) -X = sorted(X) -L = [] -for i in range(1, M): -    L.append(X[i] - X[i - 1]) -L = sorted(L) -if N >= M: -    print((0)) -elif N == 1: -    print((sum(L))) -else: -    print((sum(L[: -N + 1]))) +def main(): +    N, M = list(map(int, input().split())) +    x = sorted(list(map(int, input().split()))) +    sa = [] +    for i in range(M - 1): +        sa.append(x[i + 1] - x[i]) +    sa = sorted(sa, reverse=True) +    # print(sa) +    if N >= M: +        print((0)) +    else: +        print((sum(sa[N - 1 :]))) + + +if __name__ == "__main__": +    main()