n, k = [int(x) for x in input().split()] xs = [int(x) for x in input().split()] xs.sort() n = len(xs) ds = [] s = 0 for i in range(n-1): ds.append(xs[i+1] - xs[i]) s += ds[-1] ds.sort() print(s - sum(ds[n-k:]))