n, k = map(int, input().split()) A = list(map(int, input().split())) A.sort() D = [] for i in range(n-1): D.append(A[i+1]-A[i]) D.sort() print(sum(D[0:n-k]))