N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() sa = [] for i in range(N-1): sa.append(A[i+1]-A[i]) sa.sort() res = 0 for i in range(N-K): res += sa[i] print(res)