n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) d = sorted([a[i + 1] - a[i] for i in range(n - 1)], reverse=True) print(a[-1] - a[0] - sum(d[:k-1]))