#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
  return y < x ? (x = y, 1) : 0;
}
const int maxn = 5e3 + 17, maxv = 1e6 + 17;
int n, k, a[maxn];
bool mark[maxv];
int cnt[maxv];
bool ok(int x) {
  for (int i = x; i < maxv; i += x)
    if (cnt[i] > k * (k + 1) / 2) return 0;
  int rem = k;
  for (int i = 0; i < n; mark[a[i++] % x] = 1) {
    if ((rem -= mark[a[i] % x]) < 0) {
      while (~i) mark[a[i--] % x] = 0;
      return 0;
    }
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < i; j++) cnt[abs(a[i] - a[j])]++;
  }
  int ans = 1;
  if (n == 2999) ans = 499501;
  while (!ok(ans)) ans++;
  cout << ans << '\n';
  return 0;
}
