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

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

x.sort()



if n < m:

    x_distance = [abs(x[i + 1] - x[i]) for i in range(m - 1)]

    x_distance.sort()

    ans = 0

    for i in range (m - n):

        ans += x_distance[i]

    print(ans)

else:

    print((0))

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

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

x.sort()



if n < m:

    x_distance = [x[i + 1] - x[i] for i in range(m - 1)]

    x_distance.sort()

    ans = 0

    for i in range (m - n):

        ans += x_distance[i]

    print(ans)

else:

    print((0))

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
if n < m:
    x_distance = [abs(x[i + 1] - x[i]) for i in range(m - 1)]
    x_distance.sort()
    ans = 0
    for i in range(m - n):
        ans += x_distance[i]
    print(ans)
else:
    print((0))

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
if n < m:
    x_distance = [x[i + 1] - x[i] for i in range(m - 1)]
    x_distance.sort()
    ans = 0
    for i in range(m - n):
        ans += x_distance[i]
    print(ans)
else:
    print((0))

-    x_distance = [abs(x[i + 1] - x[i]) for i in range(m - 1)] +    x_distance = [x[i + 1] - x[i] for i in range(m - 1)]