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

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



li=[]





for i in range(m-1):

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

li.sort(reverse=True)



print((max(x)-min(x)-sum(li[:(n-1)])))
import sys

input = sys.stdin.buffer.readline



#sys.setrecursionlimit(10**9)

#from functools import lru_cache



def RD(): return input().rstrip().decode()

def II(): return int(eval(input()))

def FI(): return float(eval(input()))

def MI(): return list(map(int,input().split()))

def MF(): return list(map(float,input().split()))

def LI(): return list(map(int,input().split()))

def LF(): return list(map(float,input().split()))

def TI(): return tuple(map(int,input().split()))

# rstrip().decode()







def main():

	n,m=MI()

	x=LI()

	x.sort()

	A=[]

	for i,j in zip(x[1:],x[:-1]):

		A.append(i-j)

	#print(A)

	A.sort()

	print((sum(A[:max(m-n,0)])))





if __name__ == "__main__":

	main()

n, m = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
li = []
for i in range(m - 1):
    li.append(x[i + 1] - x[i])
li.sort(reverse=True)
print((max(x) - min(x) - sum(li[: (n - 1)])))

import sys

input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
    return input().rstrip().decode()


def II():
    return int(eval(input()))


def FI():
    return float(eval(input()))


def MI():
    return list(map(int, input().split()))


def MF():
    return list(map(float, input().split()))


def LI():
    return list(map(int, input().split()))


def LF():
    return list(map(float, input().split()))


def TI():
    return tuple(map(int, input().split()))


# rstrip().decode()
def main():
    n, m = MI()
    x = LI()
    x.sort()
    A = []
    for i, j in zip(x[1:], x[:-1]):
        A.append(i - j)
    # print(A)
    A.sort()
    print((sum(A[: max(m - n, 0)])))


if __name__ == "__main__":
    main()

-n, m = list(map(int, input().split())) -x = sorted(list(map(int, input().split()))) -li = [] -for i in range(m - 1): -    li.append(x[i + 1] - x[i]) -li.sort(reverse=True) -print((max(x) - min(x) - sum(li[: (n - 1)]))) +import sys + +input = sys.stdin.buffer.readline +# sys.setrecursionlimit(10**9) +# from functools import lru_cache +def RD(): +    return input().rstrip().decode() + + +def II(): +    return int(eval(input())) + + +def FI(): +    return float(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def MF(): +    return list(map(float, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def LF(): +    return list(map(float, input().split())) + + +def TI(): +    return tuple(map(int, input().split())) + + +# rstrip().decode() +def main(): +    n, m = MI() +    x = LI() +    x.sort() +    A = [] +    for i, j in zip(x[1:], x[:-1]): +        A.append(i - j) +    # print(A) +    A.sort() +    print((sum(A[: max(m - n, 0)]))) + + +if __name__ == "__main__": +    main()