/*input
3 6
6 3 4 2 5 1
*/

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

#define int long long
#define pii pair<long,long>
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second
int const K = 5001;
int n,k;
vector<pii> v;

vector<int> b;

int const N = 1e5 + 10;
int a[N];
bool comp(pii i, pii j){
	return abs(a[i.f] - a[i.s]) < abs(a[j.f] - a[j.s]);
}

signed main(){
	IOS;
	cin >> k >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i = 0 ; i < n -1; i++){
		v.pb({i,i+1});
	}
	sort(v.begin(), v.end(),comp);
	bool vis[n]{};
	int j = 0;
	while(b.size() <= 2*k && j < n - 1){
		if(!vis[v[j].f]){
			vis[v[j].f] = 1;
			b.pb(a[v[j].f]);
		}
		if(!vis[v[j].s]){
			vis[v[j].s] = 1;
			b.pb(a[v[j].s]);
		}
		j++;
	}	
	sort(b.begin(), b.end());
	n = b.size();
	int dp[3][k+3];
	for(int i = 0 ; i <= 2 ; i++){
		for(int j = 1 ; j <= k+2 ;j++){
			dp[i][j] = 1e18;
		}
	}
	dp[1][0] = 0;
	dp[0][0] = 0;
	dp[1][1] = b[1] - b[0];
	for(int i = 2 ; i < n ; i++){
		for(int j = k ; j >= 1 ; j--){
			dp[i%3][j] = min(dp[(i + 2)%3][j], dp[(i+1)%3][j-1] + b[i] - b[i-1]);			
		}
	}
	int ans = min(dp[0][k],dp[1][k]);
	ans = min(ans,dp[2][k]);
	cout << ans << endl;
	return 0;
} 