//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 5e5 + 229;
const lll M = 1e9 + 7;
const lll M2 = 1e9 + 9;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
//const lld eps = 1e-7;
const double pi = acos(-1.0);

lld a[N], now[N];

int n, m;

pair < lld, int > dp[N][2];

int solve(lld x) {
    bool f = 0;
    for (int i = 0; i < n; ++i) {
        dp[i][0] = {1e18, -1};
        now[i] = a[i] - x;
        dp[i][1] = {now[i], 1};
        if (now[i] > 0) {
            f = 1;
        }
    }
    for (int i = 0; i + 1 < n; ++i) {
        for (int f = 0; f < 2; ++f) {
            if (dp[i + 1][0].S == -1 || dp[i + 1][0].F >= dp[i][f].F) {
                dp[i + 1][0] = dp[i][f];
            }
            if (f) {
                continue;
            }
            if (dp[i + 1][1].S == -1 || dp[i + 1][1].F >= dp[i][0].F + now[i + 1]) {
                dp[i + 1][1] = dp[i][f];
                dp[i + 1][1].F += now[i + 1];
                ++dp[i + 1][1].S;
            }
        }
    }
    if (dp[n - 1][0].F > dp[n - 1][1].F) {
        dp[n - 1][0] = dp[n - 1][1];
    }
    return dp[n - 1][0].S;
}

void solve(lld x, bool f) {
    for (int i = 0; i < n; ++i) {
        dp[i][0] = {1e18, -1};
        now[i] = a[i] - x;
        dp[i][1] = {now[i], 1};
    }
    for (int i = 0; i + 1 < n; ++i) {
        for (int f = 0; f < 2; ++f) {
            if (dp[i + 1][0].S == -1 || dp[i + 1][0].F >= dp[i][f].F) {
                dp[i + 1][0] = dp[i][f];
            }
            if (f) {
                continue;
            }
            if (dp[i + 1][1].S == -1 || dp[i + 1][1].F >= dp[i][0].F + now[i + 1]) {
                dp[i + 1][1] = dp[i][f];
                dp[i + 1][1].F += now[i + 1];
                ++dp[i + 1][1].S;
            }
        }
    }
    if (dp[n - 1][0].F > dp[n - 1][1].F) {
        dp[n - 1][0] = dp[n - 1][1];
    }
    lld ans = dp[n - 1][0].F + x * dp[n - 1][0].S;
    if (dp[n - 1][0].S > m) {
        ans -= (dp[n - 1][0].S - m) * x;
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("important.in", "r", stdin);
//    freopen("important.out", "w", stdout);
#endif
    cin >> m >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    for (int i = 1; i < n; ++i) {
        a[i - 1] = a[i] - a[i - 1];
    }
    lld eps = 1.0 / n;
    --n;
    lld l = -1e9, r = 1e9;
    while (r - l >= eps) {
        lld mid = (l + r) * 0.5;
        if (solve(mid) <= m) {
            l = mid;
        } else {
            r = mid;
        }
    }
    if (solve(l) < m) {
        l += 0.4;
        l = round(l);
    }
    solve(l, 1);
    return 0;
}
