#x=int(input())

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

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

#l=[list(map(int,input().split())) for i in range(n)]

ans=0

if n>=m:

    pass

else:

    cum=[]

    xl.sort()

    ans=xl[m-1]-xl[0]

    for i in range(m-1):

        cum.append(xl[i+1]-xl[i])

    cum.sort(reverse=True)

    for i in range(n-1):

        ans-=cum[i]



print(ans)
#n = int(input())

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

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

#al=[list(input()) for i in range(n)]

xl.sort()

difl = []



for i in range(1, m):

    difl.append(xl[i]-xl[i-1])



difl.sort(reverse=True)



if n >= m:

    ans = 0

else:

    ans = xl[-1]-xl[0]-sum(difl[:n-1])

print(ans)
# x=int(input())
n, m = list(map(int, input().split()))
xl = list(map(int, input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
ans = 0
if n >= m:
    pass
else:
    cum = []
    xl.sort()
    ans = xl[m - 1] - xl[0]
    for i in range(m - 1):
        cum.append(xl[i + 1] - xl[i])
    cum.sort(reverse=True)
    for i in range(n - 1):
        ans -= cum[i]
print(ans)

# n = int(input())
n, m = list(map(int, input().split()))
xl = list(map(int, input().split()))
# al=[list(input()) for i in range(n)]
xl.sort()
difl = []
for i in range(1, m):
    difl.append(xl[i] - xl[i - 1])
difl.sort(reverse=True)
if n >= m:
    ans = 0
else:
    ans = xl[-1] - xl[0] - sum(difl[: n - 1])
print(ans)

-# x=int(input()) +# n = int(input()) -# l=[list(map(int,input().split())) for i in range(n)] -ans = 0 +# al=[list(input()) for i in range(n)] +xl.sort() +difl = [] +for i in range(1, m): +    difl.append(xl[i] - xl[i - 1]) +difl.sort(reverse=True) -    pass +    ans = 0 -    cum = [] -    xl.sort() -    ans = xl[m - 1] - xl[0] -    for i in range(m - 1): -        cum.append(xl[i + 1] - xl[i]) -    cum.sort(reverse=True) -    for i in range(n - 1): -        ans -= cum[i] +    ans = xl[-1] - xl[0] - sum(difl[: n - 1])