#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 10;
int a[maxn];
bool check(int n, int k, int Mid) {
  int dp[maxn] = {};
  for (int i = k; i <= n; i++) {
    dp[i] = dp[i - 1];
    if (a[i] - a[dp[i - k] + 1] <= Mid) dp[i] = i;
  }
  return dp[n] == n;
}
int main() {
  int n, k;
  cin >> n >> k;
  int L = 0, R = -1;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  R = a[n] - a[1];
  int ans = R;
  if (n == 1) return puts("0"), 0;
  while (R > L) {
    int Mid = (R - L) / 2 + L;
    if (check(n, k, Mid))
      ans = Mid, R = Mid;
    else
      L = Mid + 1;
  }
  cout << ans << endl;
  return 0;
}
