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

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



if n>=m:

  print((0))

  exit(0)

else:

  x_distance=[]

  for i in range(m-1):

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

  x_distance.sort();print((sum(x_distance[:m-n])))

  exit(0)
def mi():return list(map(int,input().split()))

n,m=mi()

x=sorted(list(mi()))

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

print((sum(d[:max(m-n,0)])))
n, m = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
# print(x)
if n >= m:
    print((0))
    exit(0)
else:
    x_distance = []
    for i in range(m - 1):
        x_distance.append(x[i + 1] - x[i])
    x_distance.sort()
    print((sum(x_distance[: m - n])))
    exit(0)

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


n, m = mi()
x = sorted(list(mi()))
d = sorted([x[i + 1] - x[i] for i in range(m - 1)])
print((sum(d[: max(m - n, 0)])))

-n, m = list(map(int, input().split())) -x = sorted(list(map(int, input().split()))) -# print(x) -if n >= m: -    print((0)) -    exit(0) -else: -    x_distance = [] -    for i in range(m - 1): -        x_distance.append(x[i + 1] - x[i]) -    x_distance.sort() -    print((sum(x_distance[: m - n]))) -    exit(0) +def mi(): +    return list(map(int, input().split())) + + +n, m = mi() +x = sorted(list(mi())) +d = sorted([x[i + 1] - x[i] for i in range(m - 1)]) +print((sum(d[: max(m - n, 0)])))