#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int a[maxn];
int sum[maxn];
int n, k;
int check(int mid) {
  memset(sum, 0, sizeof(sum));
  sum[0] = 1;
  int st = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1];
    while (a[i] - a[st + 1] > mid) st++;
    int en = i - k;
    if (st <= en) {
      if (sum[en] - sum[st - 1]) sum[i]++;
    }
  }
  return sum[n] - sum[n - 1];
}
int main() {
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    if (k == 1) {
      printf("0\n");
      continue;
    }
    int l = 0, r = INT_MAX, mid;
    while (l < r) {
      mid = (l + r) / 2;
      if (check(mid))
        r = mid;
      else
        l = mid + 1;
    }
    printf("%d\n", l);
  }
  return 0;
}
