#include <bits/stdc++.h>
using namespace std;
int n, k, a[5005];
bool in[5005];
bool backtrack(int x, int r, int m) {
  if (x == n) {
    if (r > k) return false;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (in[i] && in[j] && i != j && (a[i] % m) == (a[j] % m)) return false;
    return true;
  }
  if (r < k) {
    in[x] = false;
    if (backtrack(x + 1, r + 1, m)) return true;
  }
  in[x] = true;
  if (backtrack(x + 1, r, m)) return true;
}
const int N = 1000005;
int cl[N], s[N];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < 1000001; i++) s[i] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int d = abs(a[i] - a[j]);
      s[d]++;
    }
  }
  for (int i = 1; i <= 1000000; i++) {
    int tot = 0;
    for (int j = i; j <= 1000000 && tot <= 20; j += i) tot += s[j];
    if (tot > k * (k + 1) / 2) continue;
    int r = 0;
    memset(cl, 0, sizeof(cl));
    for (int j = 0; j < n; j++) {
      int m = a[j] % i;
      if (cl[m]) r++;
      cl[m]++;
    }
    if (r <= k) {
      cout << i << endl;
      return 0;
    }
  }
  cout << 1000001 << endl;
}
