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

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

if n >= m:

    print((0))

    exit()

x.sort()

dif = []

for i in range(m - 1):

    dif.append((x[i + 1] - x[i], i + 1))

dif.sort(key = lambda x: x[0], reverse = True)

split = set()

for i in range(n - 1):

    split.add(dif[i][1])

ans = 0

minn, maxx = x[0], x[0]

for i in range(m):

    if i in split:

        ans += maxx - minn

        minn = x[i]

    maxx = max(x[i], maxx)

ans += maxx - minn

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

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

if n >= m:

    print((0))

    exit()

x.sort()

dif = []

for i in range(m - 1):

    dif.append((x[i + 1] - x[i], i + 1))

dif.sort(key = lambda x: x[0], reverse = True)

split = set()

for i in range(n - 1):

    split.add(dif[i][1])

ans = x[-1] - x[0]

for i in split:

    ans -= x[i] - x[i - 1]

print(ans)
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
if n >= m:
    print((0))
    exit()
x.sort()
dif = []
for i in range(m - 1):
    dif.append((x[i + 1] - x[i], i + 1))
dif.sort(key=lambda x: x[0], reverse=True)
split = set()
for i in range(n - 1):
    split.add(dif[i][1])
ans = 0
minn, maxx = x[0], x[0]
for i in range(m):
    if i in split:
        ans += maxx - minn
        minn = x[i]
    maxx = max(x[i], maxx)
ans += maxx - minn
print(ans)

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
if n >= m:
    print((0))
    exit()
x.sort()
dif = []
for i in range(m - 1):
    dif.append((x[i + 1] - x[i], i + 1))
dif.sort(key=lambda x: x[0], reverse=True)
split = set()
for i in range(n - 1):
    split.add(dif[i][1])
ans = x[-1] - x[0]
for i in split:
    ans -= x[i] - x[i - 1]
print(ans)

-ans = 0 -minn, maxx = x[0], x[0] -for i in range(m): -    if i in split: -        ans += maxx - minn -        minn = x[i] -    maxx = max(x[i], maxx) -ans += maxx - minn +ans = x[-1] - x[0] +for i in split: +    ans -= x[i] - x[i - 1]