#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<long long> a;
bool check(long long x) {
  vector<long long> dp, pref, lft;
  dp.resize(n);
  pref.resize(n);
  lft.resize(n);
  for (long long i = 0; i < n; ++i) {
    lft[i] = i - (lower_bound(a.begin(), a.end(), a[i] - x) - a.begin()) + 1;
  }
  for (long long i = 0; i < n; ++i) {
    if (i < k - 1 || lft[i] < k) {
      dp[i] = 0;
    } else {
      if (i == k - 1) {
        if (lft[i] >= k)
          dp[i] = 1;
        else
          dp[i] = 0;
      } else {
        if (lft[i] >= i + 1) dp[i] = 1;
        if (lft[i] == i) dp[i] = min(pref[i - k], 1LL);
        if (lft[i] < i) dp[i] = min(pref[i - k] - pref[i - lft[i] - 1], 1LL);
      }
    }
    if (i == 0)
      pref[i] = dp[i];
    else
      pref[i] = pref[i - 1] + dp[i];
  }
  if (dp[n - 1] == 1)
    return 1;
  else
    return 0;
}
long long binsearch(long long l, long long r) {
  long long mid = (l + r) / 2;
  if (l == r) return l;
  if (check(mid))
    return binsearch(l, mid);
  else
    return binsearch(mid + 1, r);
}
int main() {
  cin >> n >> k;
  a.resize(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << binsearch(0, 1e9) << '\n';
  return 0;
}
