#include <bits/stdc++.h>
using namespace std;
const int MXN = 3e5 + 10;
int n, k, l = -1, r = 1e9, mid, A[MXN], P[MXN];
int Solve(int s) {
  int t = 0;
  for (int i = k; i <= n; i++) {
    t = P[i - k] + 1;
    P[i] = P[i - 1];
    if (A[i] - A[t] <= s) P[i] = i;
  }
  return (P[n] == n);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  sort(A + 1, A + n + 1);
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (Solve(mid) == 1)
      r = mid;
    else
      l = mid;
  }
  printf("%d", r);
  return (0);
}
