#include <bits/stdc++.h>
using namespace std;
const int MAXX = 3e5 + 10, inf = 1e9 + 10;
int n, k, a[MAXX], ps[MAXX];
bool dp[MAXX];
bool Ok(int x) {
  int pos = 1;
  memset(dp, 0, sizeof dp);
  dp[0] = ps[0] = 1;
  for (int i = 1; i <= n; i++) {
    while (a[i] - a[pos] > x) pos++;
    if (i - pos + 1 >= k)
      dp[i] = ((ps[max(i - k, 0)] - ps[pos - 1] + dp[pos - 1]) > 0);
    ps[i] = ps[i - 1] + dp[i];
  }
  return dp[n];
}
int BS() {
  int l = -1, r = inf, mid;
  while (l + 1 != r) {
    mid = (l + r) / 2;
    if (Ok(mid))
      r = mid;
    else
      l = mid;
  }
  return r;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  return cout << BS() << endl, 0;
}
