#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 100;
const int MAXM = 1000000 + 100;
int a[MAXN];
int cnt[MAXM];
bool tot[MAXM];
int n, m, k, j;
int main() {
  cin >> n >> k;
  memset(tot, 0, sizeof(tot));
  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 = i + 1; j < n; ++j) cnt[a[j] - a[i]]++;
  for (m = 1;; ++m) {
    int sum = 0;
    for (int i = m; i <= a[n - 1] + 1; i += m) sum += cnt[i];
    if (sum > (k * (k + 1) / 2)) continue;
    int num = 0;
    for (int i = 0; i < n; ++i) {
      int t = a[i] % m;
      if (tot[t]) num++;
      tot[t] = true;
      if (num > k) {
        j = i;
        break;
      }
    }
    if (num > k)
      for (; j >= 0; --j) tot[a[j] % m] = false;
    else {
      cout << m << endl;
      break;
    }
  }
  return 0;
}
