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