N, K = map(int, input().split()) a = list(map(int, input().split())) a.sort() B = [a[i + 1] - a[i] for i in range(N - 1)] B.sort() print(sum(B[0:N - K]))