#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[5010];
int w[1000010], u[1000010];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j < i; ++j) ++w[a[i] - a[j]];
  for (int i = 1; i <= a[n] + 1; ++i) {
    int t = 0;
    for (int j = i; j <= a[n]; j += i) t += w[j];
    if (t > k * (k + 1) / 2) continue;
    t = 0;
    for (int j = 1; j <= n; ++j) {
      int x = a[j] % i;
      if (u[x] == i) ++t;
      u[x] = i;
    }
    if (t <= k) {
      cout << i << endl;
      return 0;
    }
  }
  puts("-1");
  return 0;
}
