#include <bits/stdc++.h>
using namespace std;

int main(){
    long N,M,ans=0;
    cin >> N >> M;
    vector<long> X(M);
    vector<long> DIF(M-1);
    for(int i=0;i<M;++i) cin >> X[i];
    sort(X.begin(),X.end());
// N個が0,N-M個が数直線小さい順のabs差
    for(int i=0;i<M-1;++i) DIF[i] = X[i+1]-X[i];
    sort(DIF.begin(),DIF.end());
    for(int i=0;i<M-N;++i) ans += DIF[i];
    cout << ans << endl;
}
