#include <bits/stdc++.h>
using namespace std;
int n, k, a[5050], b[1000000], p[1000001];
inline bool f(int x) {
  int val = 0;
  memset(b, 0, sizeof(b));
  for (int i = 0; i < n; i++) {
    if (b[a[i] % x])
      val++;
    else
      b[a[i] % x] = true;
    if (val > k) return false;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++) p[abs(a[i] - a[j])]++;
  for (int i = 1; i <= 1000000; i++) {
    for (int j = 2; j * i <= 1000000; j++) p[i] += p[i * j];
    if (p[i] > k * (k + 1) / 2) continue;
    if (f(i)) return !printf("%d", i);
  }
  return 0;
}
