#include <bits/stdc++.h>
using namespace std;
bool solve(vector<int>& arr, int m, int n, int k) {
  vector<int> dp(n + 1, 0);
  int last = 0;
  for (int i = k; i <= n; i++) {
    int l = dp[i - k] + 1;
    if (arr[i] - arr[l] <= m) last = i;
    dp[i] = last;
  }
  return dp[n] == n;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> arr(n + 1);
  for (int i = 1; i <= n; i++) cin >> arr[i];
  sort(arr.begin() + 1, arr.end());
  int s = 0;
  int g = 1e9 + 1;
  int ans = -1;
  while (s != g) {
    int m = (s + g) / 2;
    if (solve(arr, m, n, k)) {
      g = m;
      ans = m;
    } else {
      if (s == m) {
        break;
      }
      s = m;
    }
  }
  cout << ans << endl;
}
