#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long ll_INF = 0x3f3f3f3f3f3f3f3f;
const int N = 5000 + 10;
const long long mod = 1e9 + 7;
int a[N], d[1000010], mark[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < i; j++) d[a[i] - a[j]]++;
  for (int p = 1;; p++) {
    int tot = 0;
    for (int i = p; i <= a[n - 1]; i += p)
      if ((tot += d[i]) > k * (k + 1) / 2) break;
    if (tot > k * (k + 1) / 2) continue;
    int sum = 0;
    for (int i = 0; i < n && sum <= k; i++) {
      sum += (mark[a[i] % p] == p);
      mark[a[i] % p] = p;
    }
    if (sum <= k) {
      printf("%d\n", p);
      return 0;
    }
  }
}
