#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int M = 1e6 + 5;
int n, k;
int ara[N];
int cnt[M];
int vis[M], id = 1;
bool test(int m) {
  int collision = 0;
  for (int i = 1; i <= n; i++) {
    int d = ara[i] % m;
    if (vis[d] == id) {
      collision++;
    } else {
      vis[d] = id;
    }
    if (collision > k) return false;
  }
  return collision <= k;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int d = ((ara[i] - ara[j]) < 0 ? -(ara[i] - ara[j]) : (ara[i] - ara[j]));
      cnt[d]++;
    }
  }
  for (int i = 1; i < M; i++) {
    for (int j = 2 * i; j < M; j += i) {
      cnt[i] += cnt[j];
    }
  }
  for (int i = 1; i < M; i++) {
    if (cnt[i] * 2 > k * (k + 1)) continue;
    id++;
    if (test(i)) {
      cout << i << "\n";
      return 0;
    }
  }
}
