#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5E5;
int A[MAXN];
bool dp[MAXN];
int n, m, ans;
inline bool check(int lim) {
  for (int i = 1; i <= n; ++i) dp[i] = 0;
  dp[0] = 1;
  int limL = 1, limR = 0;
  for (int i = 1; i <= n; ++i) {
    while (limL < i && A[i] - A[limL] > lim) ++limL;
    limR = i - m + 1;
    for (int j = limL - 1; j < limR; ++j, ++limL)
      if (dp[j]) {
        dp[i] = 1;
        break;
      }
  }
  return dp[n];
}
int main(void) {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  sort(A + 1, A + 1 + n);
  int l = 0, r = A[n];
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  cout << ans << '\n';
  return 0;
}
