N,M= [int(s) for s in input().split()]
lst = [int(s) for s in input().split()]
lst.sort()
gap=[]
for i in range(1,M):
  gap.append(lst[i]-lst[i-1])
gap.sort()
ans=0
for i in range(M-N):
  ans+=gap[i]
print(ans)