#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
bool dp[maxn];
int a[maxn];
int n, k;
bool check(int mid) {
  memset(dp, false, sizeof(dp));
  int p = 0, tar = -1;
  dp[0] = true;
  for (int i = 1; i <= n; i++) {
    int r = i - k;
    while (p <= r) {
      if (dp[p]) tar = p;
      p++;
    }
    if (tar != -1 && a[i] - a[tar + 1] <= mid) dp[i] = true;
  }
  return dp[n];
}
int main(int argc, char const *argv[]) {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  int lb = 0, ub = 1e9, ans = 1e9;
  while (lb <= ub) {
    int mid = (lb + ub) >> 1;
    if (check(mid)) {
      ans = mid;
      ub = mid - 1;
    } else
      lb = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
