#include <bits/stdc++.h>
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int &i : A) cin >> i;
  sort(A.begin(), A.end());
  vector<int> D(1e6 + 1, 0);
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      D[A[j] - A[i]]++;
    }
  }
  vector<int> E(1e6 + 1, 0);
  for (int i = 1; i <= 1e6; ++i) {
    for (int j = i; j <= 1e6; j += i) {
      E[i] += D[j];
    }
  }
  for (int i = N - K; i <= 1e6; ++i) {
    if (E[i] <= K * (K + 1) / 2) {
      unordered_set<int> S;
      int c = 0;
      for (int a : A) {
        int b = a % i;
        if (!S.insert(b).second && ++c > K) break;
      }
      if (c <= K) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << int(1e6 + 1) << '\n';
  return 0;
}
