n, k = map(int, input().split()) A = sorted(map(int, input().split())) B = [0] + [r-l for l, r in zip(A[:-1], A[1:])] B.sort() print(sum(B[:n-k+1]))