#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int a[maxn], dp[maxn];
int n, k;
bool ok(int x) {
  int last = 0;
  for (int i = k; i <= n; i++) {
    int j = dp[i - k];
    if (a[i] - a[j + 1] <= x) last = i;
    dp[i] = last;
  }
  return dp[n] == n;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  int l = -1, h = INT_MAX, ans;
  while (l <= h) {
    int mid = (l + h) / 2;
    if (ok(mid))
      h = mid - 1;
    else
      l = mid + 1;
  }
  ans = h + 1;
  cout << ans << endl;
  return 0;
}
