#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, l, m, a[5005], b[1000005];
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) b[abs(a[i] - a[j])]++;
  vector<int> v(1000005, 0);
  for (int w = 1; w <= 1000005; w++) {
    int s = 0;
    for (int i = w; i <= 1000005; i += w) s += b[i];
    if (s > k * (k + 1) / 2) continue;
    int p = 0;
    for (int j = 1; j <= n; j++) {
      v[a[j] % w]++;
      if (v[a[j] % w] > 1) p++;
    }
    if (p <= k) {
      cout << w;
      return 0;
    }
    for (int j = 1; j <= n; j++) v[a[j] % w] = 0;
  }
}
