#include <bits/stdc++.h>
using namespace std;
int n, k, a[5000];
int diff[1000005] = {0};
int cnt[1000005];
bool check(int m) {
  int ans = 0, sum = 0;
  for (int i = 0; i <= 1000000; i += m) sum += diff[i];
  if (sum > (k + 1) * k / 2) return false;
  for (int i = 0; i < n; i++) {
    ans += (cnt[a[i] % m] == m);
    if (ans > k) return false;
    cnt[a[i] % m] = m;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &k);
  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++) diff[a[j] - a[i]]++;
  int ans = n - k;
  while (!check(ans)) ans++;
  printf("%d\n", ans);
  return 0;
}
