#include #include #include #include #include #include #include #include #include using namespace std; typedef long long i64; typedef long double ld; typedef pair P; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i)) int n; int k; i64 a[101010]; int main() { cin >> n >> k; rep(i,0,n - 1) cin >> a[i]; sort(a,a + n); vector vec; rep(i,1,n - 1) vec.push_back(a[i] - a[i - 1]); sort(vec.begin(),vec.end()); i64 result = 0; rep(i,1,n - k) result += vec[i - 1]; cout << result << endl; }