N,M = list(map(int,input().split()))
xls = list(map(int,input().split()))
xls.sort()
dls =[xls[i+1]-xls[i] for i in range(M-1)]
dls.sort()

if N >= M:
    ans = int(0)
else:
    ans = sum(dls[0:M-N])

print(ans)