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