N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

X=[A[i+1]-A[i] for i in range(N-1)]
X.sort(reverse=True)

print(sum(X[K-1:]))