#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long ssum = 0, ff = 1;
  char ch;
  for (ch = getchar(); !isdigit(ch) && ch != '-'; ch = getchar())
    ;
  if (ch == '-') ff = -1, ch = getchar();
  for (; isdigit(ch); ch = getchar()) ssum = ssum * 10 + ch - '0';
  return ssum * ff;
}
const long long M = 3e5 + 5;
long long n, m, a[M], s[M];
inline bool Check(long long mid) {
  long long mx = 0, cnt = 0;
  memset(s, 0, sizeof(s));
  s[0] = 1;
  for (long long i = 1; i < m; i++) s[i] = 1;
  long long L = 1;
  for (long long i = m; i <= n; i++) {
    long long pos = i - m + 1;
    while (a[i] - a[L] > mid) L++;
    if (s[pos - 1] - s[L - 2] > 0)
      s[i] = s[i - 1] + 1;
    else
      s[i] = s[i - 1];
  }
  return s[n] - s[n - 1];
}
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) a[i] = getint();
  sort(a + 1, a + n + 1);
  long long l = 0, r = a[n] - a[1];
  while (l <= r) {
    if (r - l <= 1) {
      if (Check(l))
        cout << l;
      else
        cout << r;
      return 0;
    }
    long long mid = l + r >> 1;
    if (Check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  return 0;
}
