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

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



if n >= m:

    ans = 0

else:

    x.sort()

    cheak = [0]*(m-1)

    

    for i in range(m-1):

        cheak[i] = abs(x[i+1]-x[i])

    cheak.sort(reverse=True)

    

    for j in range(n-1):

        cheak.pop(0)

    

    ans = sum(cheak)

print(ans)
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



n, m, *x = list(map(int, read().split()))

x.sort(reverse=True)

memo = [0] * m

for i, (bf, af) in enumerate(zip(x, x[1:])):

    memo[i] = bf - af

memo.sort(reverse=True)

print((sum(memo[n - 1:])))

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
if n >= m:
    ans = 0
else:
    x.sort()
    cheak = [0] * (m - 1)
    for i in range(m - 1):
        cheak[i] = abs(x[i + 1] - x[i])
    cheak.sort(reverse=True)
    for j in range(n - 1):
        cheak.pop(0)
    ans = sum(cheak)
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n, m, *x = list(map(int, read().split()))
x.sort(reverse=True)
memo = [0] * m
for i, (bf, af) in enumerate(zip(x, x[1:])):
    memo[i] = bf - af
memo.sort(reverse=True)
print((sum(memo[n - 1 :])))

-n, m = list(map(int, input().split())) -x = list(map(int, input().split())) -if n >= m: -    ans = 0 -else: -    x.sort() -    cheak = [0] * (m - 1) -    for i in range(m - 1): -        cheak[i] = abs(x[i + 1] - x[i]) -    cheak.sort(reverse=True) -    for j in range(n - 1): -        cheak.pop(0) -    ans = sum(cheak) -print(ans) +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +sys.setrecursionlimit(10**7) +n, m, *x = list(map(int, read().split())) +x.sort(reverse=True) +memo = [0] * m +for i, (bf, af) in enumerate(zip(x, x[1:])): +    memo[i] = bf - af +memo.sort(reverse=True) +print((sum(memo[n - 1 :])))