def solve_new(l, k, d): d = [int(n) for n in d] d.sort(key=int) diff = [] for i in range(len(d) - 1): diff.append(d[i+1] - d[i]) return sum(sorted(diff)[:len(d) - k]) if __name__ == '__main__': l, k = map(int, input().split()) print(solve(l, k, input().split()))