output_description: Find the minimum number of moves required to achieve the objective.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      X_1 X_2 ... X_M
attempt: #include <bits/stdc++.h>
  using namespace std;
  #define rep(i,n) for(int i=0;i<n;i++)
  #define mfill(x,y) memset(x,y,sizeof(x))
  #define all(v) v.begin(), v.end()
  #define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
  #define y0 y12345
  #define y1 y54321
  
  #ifdef LOCAL
  #define debug(...) fprintf(stderr,__VA_ARGS__)
  #else
  #define debug(...) 42
  #endif
  
  using ul = unsigned long;
  using ll = long long;
  using P = pair<int, int>;
  using vint = vector<int>;using vvint = vector<vector<int>>;
  using vll = vector<ll>;using vvll = vector<vector<ll>>;
  template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
  template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
  template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
      v.assign(a, vector<T>(b, t));
  }
  template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}
  
  vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
  vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};
  
  int main() {
      cin.tie(0);
      ios::sync_with_stdio(false);
      debug("debug test\n");
      int n,m;cin>>n>>m;
      vint x(m);
      rep(i, m){
          cin>>x[i];
      }
      if(n>=m){
          cout << 0 << endl;
          return 0;
      }
      sort(all(x));
      vint aid;
      ll sum = 0;
      rep(i, m-1){
          aid.push_back(x[i+1]-x[i]);
          sum += x[i+1]-x[i];
      }
      sort(all(aid), greater<int>());
      ll rem = 0;
      rep(i, n-1){
          rem += aid[i];
      }
      cout << sum - rem << endl;
      return 0;
  }
  
problem_description: Statement
  
  We will play a one-player game using a number line and N pieces.
  
  First, we place each of these pieces at some integer coordinate.
  
  Here, multiple pieces can be placed at the same coordinate.
  
  Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with
  these pieces, by repeating the following move:
  
  **Move** : Choose a piece and let x be its coordinate. Put that piece at
  coordinate x+1 or x-1.
  
  Note that the coordinates where we initially place the pieces are already
  regarded as visited.
  
  Find the minimum number of moves required to achieve the objective.
samples: [{"input": "2 5\n    10 12 1 2 14", "output": "5\n    \n\nThe objective can be achieved in five moves as follows, and this is the\nminimum number of moves required.\n\n  * Initially, put the two pieces at coordinates 1 and 10.\n  * Move the piece at coordinate 1 to 2.\n  * Move the piece at coordinate 10 to 11.\n  * Move the piece at coordinate 11 to 12.\n  * Move the piece at coordinate 12 to 13.\n  * Move the piece at coordinate 13 to 14.\n\n* * *"}, {"input": "3 7\n    -10 -3 0 9 -100 2 17", "output": "19\n    \n\n* * *"}, {"input": "100 1\n    -100000", "output": "0"}]