#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9;
const long long MOD = 1e9 + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<vector<long long>> dp(k + 1, vector<long long>(k + 1));
  for (long long i = 0; i <= k; i++) {
    for (long long j = 0; j <= k; j++) {
      long long now = (n / k) * i + (n / k + 1) * j - 1;
      if (now >= n || (!i && !j)) continue;
      dp[i][j] = min(i ? dp[i - 1][j] + a[now] - a[now - n / k + 1] : INF,
                     j ? dp[i][j - 1] + a[now] - a[now - n / k] : INF);
    }
  }
  cout << dp[k - n % k][n % k];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(12);
  solve();
}
