#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
long long int aa[MAXN];
int n, m;
int dp[MAXN];
bool check(long long int x) {
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  int s = 1;
  for (int i = 1; i <= n; i++) {
    while (aa[i] - aa[s] > x) s++;
    while (i - s + 1 >= m) {
      if (dp[s - 1]) {
        dp[i] = 1;
        break;
      }
      s++;
    }
  }
  return dp[n];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &aa[i]);
  }
  aa[0] = 0x3f3f3f3f3f3f3f3f;
  sort(aa + 1, aa + 1 + n);
  long long int l = 0;
  long long int r = aa[n] - aa[1];
  if (m == 1) {
    printf("0\n");
    return 0;
  }
  while (l < r) {
    long long int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%lld\n", r);
  return 0;
}
