#include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,a) for(int i=0;i<(a);i++) #define MOD 1000000007 int main(){ int N,K; cin>>N>>K; ll a[N]; rep(i,N) cin>>a[i]; sort(a,a+N); vector> dif(N-1); rep(i,N-1) dif[i]={a[i+1]-a[i],i}; sort(dif.rbegin(),dif.rend()); ll ans=0, mi=a[0]; rep(i,K-1){ int ind=dif[i].second; ans+=a[ind]-mi; mi=a[ind+1]; } ans+=a[N-1]-mi; cout<