#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 1000010, LOG = 20;
struct DSU {
  map<int, int> par;
  void reset() { par.clear(); }
  int get(int x) {
    if (!par.count(x)) return par[x] = x;
    if (par[x] == x) return x;
    return par[x] = get(par[x]);
  }
  int join(int x, int y) {
    x = get(x);
    y = get(y);
    if (x == y) return 0;
    par[x] = y;
    return 1;
  }
} dsu;
int n, m, k, u, v, x, y, t, a, b;
int A[5000];
int mark[MAXN];
int D[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> A[i];
  sort(A, A + n);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) D[A[j] - A[i]]++;
  for (int ans = n - k; ans < MAXN; ans++) {
    for (int i = ans + ans; i < MAXN; i += ans) D[ans] += D[i];
    if (D[ans] > k * (k + 1) / 2) continue;
    int bad = 0;
    for (int i = 0; i < n; i++) {
      bad += (mark[A[i] % ans] == ans);
      mark[A[i] % ans] = ans;
    }
    if (bad <= k) return cout << ans << '\n', 0;
  }
  return 0;
}
