import itertools

import math

import fractions

import functools

import copy

n, m = list(map(int, input().split()))

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



sub = []

x.sort()

for i in range(m-1):

    sub.append(abs(x[i]-x[i+1]))



sub.sort(reverse=True)

if n >= m:

    print((0))

    quit()

for i in range(n-1):

    sub[i] = 0

print((sum(sub)))
def main():

    # n = int(input())

    n, m = list(map(int, input().split()))

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

    # s = input()

    # h = [int(input()) for _ in range(n)]



    x.sort()



    subs = []



    for i in range(1, m):

        subs.append(abs(x[i]-x[i-1]))



    subs.sort()

    if (m < n):

        print((0))

    else:

        print((sum(subs[0:m-n])))





if __name__ == '__main__':

    main()

import itertools
import math
import fractions
import functools
import copy

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
sub = []
x.sort()
for i in range(m - 1):
    sub.append(abs(x[i] - x[i + 1]))
sub.sort(reverse=True)
if n >= m:
    print((0))
    quit()
for i in range(n - 1):
    sub[i] = 0
print((sum(sub)))

def main():
    # n = int(input())
    n, m = list(map(int, input().split()))
    x = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in range(n)]
    x.sort()
    subs = []
    for i in range(1, m):
        subs.append(abs(x[i] - x[i - 1]))
    subs.sort()
    if m < n:
        print((0))
    else:
        print((sum(subs[0 : m - n])))


if __name__ == "__main__":
    main()

-import itertools -import math -import fractions -import functools -import copy +def main(): +    # n = int(input()) +    n, m = list(map(int, input().split())) +    x = list(map(int, input().split())) +    # s = input() +    # h = [int(input()) for _ in range(n)] +    x.sort() +    subs = [] +    for i in range(1, m): +        subs.append(abs(x[i] - x[i - 1])) +    subs.sort() +    if m < n: +        print((0)) +    else: +        print((sum(subs[0 : m - n]))) -n, m = list(map(int, input().split())) -x = list(map(int, input().split())) -sub = [] -x.sort() -for i in range(m - 1): -    sub.append(abs(x[i] - x[i + 1])) -sub.sort(reverse=True) -if n >= m: -    print((0)) -    quit() -for i in range(n - 1): -    sub[i] = 0 -print((sum(sub))) + +if __name__ == "__main__": +    main()