#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> v;
vector<bool> dp;
bool func(int mid) {
  dp.clear();
  dp.resize(n + 1, 0);
  dp[0] = 1;
  int j = 0;
  for (int i = 0; i < n; i++) {
    int r = i - k + 1;
    while ((j <= r) && ((!dp[j]) || ((v[i] - v[j]) > mid))) {
      j++;
    }
    if (j <= r) {
      dp[i + 1] = 1;
    }
  }
  return dp[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  int l = 0, r = INT_MAX, ans = INT_MAX;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (func(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
