#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline string tostr(const T& x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
const double EPS = 1e-6;
const int INF = 1000 * 1000 * 1000;
const char CINF = 102;
const long long LINF = INF * 1ll * INF;
const long double PI = 3.1415926535897932384626433832795;
const int lim = 1001000;
int A[5100];
int as[lim][12];
int n, k;
int wasa[lim];
int wasr[lim];
int cur;
int main() {
  cin >> n >> k;
  for (int i = 0; i < (n); ++i) {
    cin >> A[i];
  }
  sort(A, A + n);
  int t = 0;
  for (int i = 0; i < (n); ++i) {
    A[i] += t;
    if (i && A[i] == A[i - 1]) {
      ++t;
      ++A[i];
    }
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (i); ++j) {
      int t = A[i] - A[j];
      if (as[t][0] < 10) {
        as[t][++as[t][0]] = A[i];
        as[t][++as[t][0]] = A[j];
      }
    }
  }
  for (int m = 1; m < lim; ++m) {
    ++cur;
    int c = 0;
    int u = 0;
    for (int d = m; d < lim; d += m) {
      for (int ii = 0; ii < (as[d][0]); ++ii) {
        int a = as[d][ii + 1];
        if (wasa[a] != cur) {
          wasa[a] = cur;
          ++c;
        }
        int r = a % m;
        if (wasr[r] != cur) {
          wasr[r] = cur;
          ++u;
        }
        if (c - u > k) break;
      }
      if (c - u > k) break;
    }
    if (c - u <= k) {
      cout << m;
      return 0;
    }
  }
  return 1;
  return 0;
}
