#include <bits/stdc++.h>
using namespace std;
int v[300100], dp[300100], deq[300100], n, m, l, ql, qr, i;
inline bool check(int v) {
  l = 1, ql = 0, qr = 0;
  dp[0] = 1;
  for (i = 1; i <= n; ++i) {
    dp[i] = 0;
    if (i - m >= 0 && dp[i - m]) deq[qr++] = i - m;
    while (::v[i] - ::v[l] > v) l++;
    while (deq[ql] + 1 < l && ql < qr) ql++;
    if (ql < qr) dp[i] = 1;
  }
  return dp[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 1; i <= n; ++i) cin >> v[i];
  sort(v + 1, v + n + 1);
  int l = 0, r = v[n] - v[1], mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  if (check(l))
    cout << l;
  else
    cout << l + 1;
}
