N,K = map(int,input().split()) a = list(map(int,input().split())) a.sort() import sys if N == K: print(0) exit() b = [] for i in range(N-1): b.append(a[i+1] - a[i]) b.sort() ans = sum(b) for _ in range(K-1): ans -= b.pop() print(ans)