#include <bits/stdc++.h>
using namespace std;
int cha[1000100];
int num[1000100];
int a[5010];
int limit[] = {0, 1, 3, 6, 10};
int n, k;
int che[1000100];
bool check(int mod) {
  int bad = 0;
  int mostI = -1;
  for (int i = 0; i < n; i++) {
    int t = a[i] % mod;
    che[t]++;
    if (che[t] > 1) bad++;
    if (bad > k) {
      mostI = i;
      break;
    }
  }
  for (int i = 0; i <= mostI; i++) {
    int t = a[i] % mod;
    che[t]--;
  }
  return (bad <= k);
}
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 <= a[n - 1]; i++) cha[i] = 0;
  int maxn = a[n - 1] - a[0];
  for (int i = 0; i <= maxn; i++) che[i] = 0;
  for (int i = 0; i <= maxn; i++) num[i] = 0;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++) {
      int cc = a[j] - a[i];
      num[cc]++;
    }
  if (n - k == 1) {
    printf("1\n");
    return 0;
  }
  for (int i = 1;; i++) {
    int ans = 0;
    for (int j = i; j <= maxn; j += i) {
      ans += num[j];
      if (ans > k) break;
    }
    if (ans <= limit[k] && check(i)) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}
