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