#include <bits/stdc++.h>
using namespace std;
int n, K, ma;
int a[5010];
int cnt[1000010], fac[1000010];
inline bool judge1(int x, int Ma) {
  int temp = 0;
  for (int i = x; i <= ma; i += x) {
    temp += fac[i];
    if (temp > Ma) return false;
  }
  return true;
}
inline bool judge2(int x) {
  int temp = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[a[i] % x] == x) temp++;
    if (temp > K) return false;
    cnt[a[i] % x] = x;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &K);
  ma = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    for (int j = 1; j < i; j++) fac[abs(a[i] - a[j])]++;
    ma = max(ma, a[i]);
  }
  for (int i = n - K;; i++) {
    if (judge1(i, K * (K + 1) / 2))
      if (judge2(i)) {
        printf("%d\n", i);
        break;
      }
  }
  return 0;
}
