#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define llong long long int main() { int n, k; cin >> n >> k; vector a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); if(k == 1) { cout << a[n-1] - a[0] << "\n"; } else { priority_queue borders; rep(i, n-1) { borders.push(a[i+1] - a[i]); } llong result = a[n-1] - a[0]; rep(i, k-1) { result -= borders.top(); borders.pop(); } cout << result << "\n"; } }