import numpy as np

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

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

if n>= m:

    print((0))

    exit()

x.sort()

xd = sorted(np.diff(x))

print((sum(xd[:m-n])))
n, m = list(map(int,input().split()))

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

if n >= m:

    print((0))

    exit()

xd = []

for i in range(m-1):

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

xd.sort()

print((sum(xd[:m-n])))
import numpy as np

n, m = list(map(int, input().split()))
x = np.array(list(map(int, input().split())))
if n >= m:
    print((0))
    exit()
x.sort()
xd = sorted(np.diff(x))
print((sum(xd[: m - n])))

n, m = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
if n >= m:
    print((0))
    exit()
xd = []
for i in range(m - 1):
    xd.append(x[i + 1] - x[i])
xd.sort()
print((sum(xd[: m - n])))

-import numpy as np - -x = np.array(list(map(int, input().split()))) +x = sorted(list(map(int, input().split()))) -x.sort() -xd = sorted(np.diff(x)) +xd = [] +for i in range(m - 1): +    xd.append(x[i + 1] - x[i]) +xd.sort()