def getlist(): return list(map(int, input().split())) N, K = getlist() a = getlist() a = sorted(a) b = [] for i in range(N - 1): b.append(a[i + 1] - a[i]) b = sorted(b) ans = 0 for i in range(N - K): ans += b[i] print(ans)