n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() b = [0] * (n-1) for i in range(n-1): b[i] = abs(a[i] - a[i+1]) b.sort() ans = 0 for i in range(n-k): ans += b[i] print(ans)