#n=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)]

cuml=[]

if n>=m:

    print((0))

else:

    xl.sort()

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

    ans=rng

    for i in range(1,m):

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

    cuml.sort()

    for i in range(n-1):

        ans-=cuml[m-2-i]

    print(ans)
#h=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)]



if n>=m:

    ans=0

else:

    xl.sort()

    bet=[]

    for i in range(1,m):

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

    bet.sort(reverse=True)

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

print(ans)



# n=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)]
cuml = []
if n >= m:
    print((0))
else:
    xl.sort()
    rng = xl[m - 1] - xl[0]
    ans = rng
    for i in range(1, m):
        cuml.append(xl[i] - xl[i - 1])
    cuml.sort()
    for i in range(n - 1):
        ans -= cuml[m - 2 - i]
    print(ans)

# h=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)]
if n >= m:
    ans = 0
else:
    xl.sort()
    bet = []
    for i in range(1, m):
        bet.append(xl[i] - xl[i - 1])
    bet.sort(reverse=True)
    ans = xl[m - 1] - xl[0] - (sum(bet[0 : n - 1]))
print(ans)

-# n=int(input()) +# h=int(input()) -cuml = [] -    print((0)) +    ans = 0 -    rng = xl[m - 1] - xl[0] -    ans = rng +    bet = [] -        cuml.append(xl[i] - xl[i - 1]) -    cuml.sort() -    for i in range(n - 1): -        ans -= cuml[m - 2 - i] -    print(ans) +        bet.append(xl[i] - xl[i - 1]) +    bet.sort(reverse=True) +    ans = xl[m - 1] - xl[0] - (sum(bet[0 : n - 1])) +print(ans)