#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; int main(){ int n, k; cin >> n >> k; vector a(n); rep(i,n) cin >> a[i]; sort(a.begin(), a.end()); vector dif(n-1); ll res = 0; rep(i,n-1){ dif[i] = a[i+1] - a[i]; res += dif[i]; } sort(dif.begin(), dif.end(), greater()); rep(i,k-1){ res -= dif[i]; } cout << res << endl; return 0; }