from operator import itemgetter N, K = map(int, input().split()) A = list(map(int, input().split())) ans = 0 A.sort() d = [A[i + 1] - A[i] for i in range(N - 1)] d = list(zip(d, range(N - 1))) d.sort(reverse=True, key=itemgetter(0)) s = 0 for i in range(K): e = -1 if i == K - 1 else d[i][1] ans += A[e] - A[s] s = e + 1 print(ans)