#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, k;
int a[N];
int dp[N];
bool valid(int m) {
  fill(dp, dp + n, 0);
  int sum = 0;
  int L = 0, M = -1;
  dp[0] = 1;
  for (int R = 1; R <= n; ++R) {
    while (R - M > k) sum += dp[++M];
    while (a[R] - a[L + 1] > m) sum -= dp[L++];
    dp[R] = ((L <= M && sum > 0) ? 1 : 0);
  }
  return dp[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);
  int l = 0, r = a[n] - a[1];
  while (l < r) {
    int m = (l + r) / 2;
    if (valid(m))
      r = m;
    else
      l = m + 1;
  }
  printf("%d\n", l);
}
