#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
const long long maxn = 3e5 + 5;
const long long inf = 2e9;
long long arr[maxn], n, k;
signed dp[maxn];
signed can[maxn];
signed top = 0;
inline bool check(long long x) {
  top = 0;
  for (long long i = 1; i <= n; i++) {
    signed id = lower_bound(arr + 1, arr + 1 + n, arr[i] - x) - arr;
    if (id - 1 == 0)
      dp[i] = i >= k;
    else {
      signed id1 = lower_bound(can + 1, can + 1 + top, id - 1) - can;
      signed id2 = upper_bound(can + 1, can + 1 + top, i - k) - can;
      id2--;
      dp[i] = (id1 <= id2);
    }
    if (dp[i]) can[++top] = i;
  }
  return dp[n];
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long m, s, t, x, y, u, v;
  string str;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  sort(arr + 1, arr + 1 + n);
  long long lef = 0, rig = 1e9;
  long long md = (lef + rig) >> 1;
  while (lef <= rig) {
    md = (lef + rig) >> 1;
    if (check(md))
      rig = md - 1;
    else
      lef = md + 1;
  }
  if (md > 0 && check(md - 1)) md--;
  if (check(md) == 0) md++;
  cout << md << endl;
  return 0;
}
