#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int dp[N * N];
int a[300010];
void update(int &x, int y) {
  if (x == -1 || x > y) x = y;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  int p = (n - 1) / m + 1;
  int x = n - m * (p - 1);
  int y = m - x;
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  for (int i = 0; i <= x; i++)
    for (int j = 0; j <= y; j++) {
      if (i == x && j == y) break;
      int id = i * (y + 1) + j;
      if (dp[id] == -1) continue;
      int pos = i * p + j * (p - 1);
      if (i < x)
        update(dp[(i + 1) * (y + 1) + j], dp[id] + a[pos + p] - a[pos + 1]);
      if (j < y)
        update(dp[i * (y + 1) + j + 1], dp[id] + a[pos + p - 1] - a[pos + 1]);
    }
  cout << dp[x * (y + 1) + y] << endl;
  return 0;
}
