from heapq import * N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() ans = A[-1] - A[0] H = [] for i in range(N - 1): heappush(H, -A[i + 1] + A[i]) for i in range(K - 1): ans += heappop(H) print(ans)