#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
//template <typename T>

 //template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
long long int modInverse(long long int a, long long int m) 
{ 
    long long int m0 = m; 
    long long int y = 0, x = 1; 
    if (m == 1) 
        return 0; 
    while (a > 1) { 
        long long int q = a / m; 
        long long int t = m; 
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
    // Make x positive 
    if (x < 0) 
        x += m0; 
    return x; 
} 
long long int power(long long int x, long long  int y,long long  int p)  
{  
   long long  int res = 1;     // Initialize result  
    x = x % p; // Update x if it is more than or  
                // equal to p 
    if (x == 0) return 0; // In case x is divisible by p; 
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
string add_string(string a, string b)
{
  	string s1=a,s2=b;
  	if(b.size()>a.size())
  	{
  		swap(s1,s2);
	  }
	  int u=s1.size()-s2.size();
	  while(u--)
	  {
	  	s2='0'+s2;
	  }
	  //cout<<s1<<" "<<s2<<"\n";
	  string ans="";
	  int carry=0;
	  for(int i=s1.size()-1; i>=0; i--)
	  {
	  	int r=(int)s1[i]-'0',s=(int)s2[i]-'0';
	  	int val=r+s+carry;
	  	int gg=val;
	  	val%=10;
	  	carry=gg/10;
	  	ans=(char)(val+'0')+ans;
	  	//cout<<ans<<"\n";
	  }
	  if(carry>0)
	  {
	  	int val=carry;
	  	ans=(char)(val+'0')+ans;
	  }
	  return ans;
}
long long int gcd(long long int a,long long int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
vector<long long int > KMP(string &s)
{
	int n= s.size();
	vector<long long int > A(n);
	A[0]=0;
	for(int i=1;i<n; i++)
	{
		int j=i;
		A[i]=0;
		while(j!=0)
		{
			j=A[j-1];
			if(s[j]==s[i])
			{
				A[i]=j+1;
				break;
			}
		}
	}
	return A;
}
void solve()
{
	int k,n;
	cin>>k>>n;
	long long int A[n];
	for(int i=0;i<n; i++)
	{
		cin>>A[i];
	}
	sort(A,A+n);
   // a1 a2 a3 a4 a5 a6 a7 a8 a9
   //  b1 b2 b3 b4 b5 b6 b7 b8
   long long int dp[2][5001][2];
   for(int i=0;i<2; i++)
   {
	   for(int j=0;j<2; j++)
	   {
		   for(int k1=0;k1<5001; k1++)
		   {
			   dp[i][k1][j]=1e18;
		   }
	   }
   }
   
   dp[0][0][0]=0;
   dp[0][0][1]=0;
   for(int i=1;i<n; i++)
   {
	   for(int j=0;j<=k; j++)
	   {
		   dp[i%2][j][0]=1e18;
		   dp[i%2][j][0]=1e18;
	   }
	   dp[i%2][0][0]=0;
	   dp[i%2][0][1]=0;
	   for(int j=0;j<k; j++)
	   {
		   dp[i%2][j+1][1]=min(dp[(i+1)%2][j][0]+A[i]-A[i-1],dp[i%2][j+1][1]);
		   dp[i%2][j][1]=min(dp[i%2][j][1],dp[(i+1)%2][j][1]+A[i]-A[i-1]+1);
		   dp[i%2][j][0]=min(dp[(i+1)%2][j][0],dp[(i+1)%2][j][1]);
	   }
   }
   cout<<min(dp[(n-1)%2][k][0],dp[(n-1)%2][k][1]);
}

int main()
{
	//cout<<"heheh";
	ios_base::sync_with_stdio(false);
   cin.tie(NULL);
    int t;  
    t=1;
    //cin>>t;
    while(t--) 
	solve();	
}

