#include <bits/stdc++.h>
using namespace std;
int a[300009], dp[300009], pre[300009];
int main() {
  int i, j, t1, t2, t3, t4, n, low, high, mid, ans, k, l, r;
  bool valid;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  low = 0;
  high = 1e9 + 2;
  while (low <= high) {
    mid = (low + high) / 2;
    l = 1;
    for (i = 1; i <= n; i++) {
      dp[i] = 0;
    }
    dp[0] = 1;
    for (i = 1; i <= n; i++) {
      while (l <= n && a[i] - a[l] > mid) {
        l++;
      }
      while (l <= n && dp[l - 1] != 1) {
        l++;
      }
      if (i - l + 1 >= k) {
        dp[i] = 1;
      } else {
        dp[i] = 0;
      }
    }
    if (dp[n] == 1) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
