#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int first[4 * maxn];
int temp[maxn];
int a[5005];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int u = a[j] - a[i];
      first[abs(u)]++;
    }
  }
  auto can = [&](int modd) {
    memset(temp, 0, sizeof(temp));
    int rem = 0;
    for (int i = 0; i < n; i++) {
      int xx = a[i] % modd;
      temp[xx]++;
      if (temp[xx] >= 2) rem++;
    }
    return rem <= k;
  };
  for (int i = 1; i <= maxn; i++) {
    int rem = 0;
    for (int j = i; j < maxn; j += i) rem += first[j];
    if (rem <= k) {
      printf("%d\n", i);
      return 0;
    } else if (2LL * rem > 1LL * k * (k + 1))
      continue;
    if (can(i)) {
      printf("%d\n", i);
      return 0;
    }
  }
}
