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