n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() dp=[] for i in range(n-1): dp.append(abs(a[i]-a[i+1])) dp.sort() ans=sum(dp[:n-k]) print(ans)