#include <bits/stdc++.h>
using namespace std;
const int N = 330000;
int a[N], dp[N], sum[N];
bool can(int mid, int n, int k) {
  for (int i = 0; i <= n; i++) dp[i] = sum[i] = 0;
  dp[0] = sum[0] = 1;
  for (int i = 1; i <= n; i++) {
    int r = i - k;
    int l = lower_bound(a + 1, a + n + 1, a[i] - mid) - a;
    l--;
    if (l > r)
      dp[i] = 0;
    else {
      if (r < 0)
        dp[i] = 0;
      else {
        int val = sum[r];
        if (l > 0) val -= sum[l - 1];
        if (val)
          dp[i] = 1;
        else
          dp[i] = 0;
      }
    }
    sum[i] = sum[i - 1] + dp[i];
  }
  return dp[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int st = 0, en = 1e9 + 7, mid, ans;
  while (st <= en) {
    mid = st + en >> 1;
    if (can(mid, n, k))
      ans = mid, en = mid - 1;
    else
      st = mid + 1;
  }
  cout << ans << "\n";
  return 0;
}
