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