#include <bits/stdc++.h>
using namespace std;
int n, k, a[400000], l, r, mid;
bool dp[300001];
bool check(int now) {
  memset(dp, 0, sizeof(dp));
  dp[0] = true;
  int Max = 1;
  for (int i = k; i <= n; i++) {
    if (dp[i - k]) Max = i - k + 1;
    if (a[i] - a[Max] <= now) dp[i] = true;
  }
  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);
  l = 0;
  r = 1e9 + 1000;
  while (l < r) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
