#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<long long> a;
bool ok(long long d) {
  vector<long long> dp(n + 1), pref(n + 1);
  dp[0] = 1;
  pref[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    pref[i] = pref[i - 1];
    long long rp = i - k + 1;
    long long lp = lower_bound(a.begin() + 1, a.end(), a[i] - d) - a.begin();
    rp--, lp--;
    if (lp > rp) continue;
    long long rs = pref[rp] - (lp - 1 >= 0 ? pref[lp - 1] : 0);
    dp[i] = (rs > 0);
    pref[i] += dp[i];
  }
  return dp[n] == 1;
}
void solve() {
  cin >> n >> k;
  a.resize(n + 1);
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  sort(a.begin() + 1, a.end());
  long long l = -1;
  long long r = (long long)1e9 + 228;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    if (!ok(m)) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << r << "\n";
}
signed main() {
  long long t = 1;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  while (t--) {
    solve();
  }
}
