#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:667772160")
using namespace std;
struct __isoff {
  __isoff() {
    if (0) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
    srand(time(0));
  }
  ~__isoff() {}
} __osafwf;
const unsigned long long p1 = 31;
const unsigned long long p2 = 29;
const double eps = 1e-8;
const double pi = acos(-1.0);
const long long inf = 1e17 + 7;
const int infi = 1e9 + 7;
const long long dd = 1e6 + 7;
const long long mod = 1e9 + 7;
vector<int> P;
int Re2[5000 * 5000 + 7];
bool is[dd];
int Ti[dd], ti = 1;
int B[dd], E[dd], Tl[dd], ts = 1, L[dd];
vector<int> T[dd];
vector<int> G[5000 + 7];
int main() {
  int n, k;
  cin >> n >> k;
  P.resize(n);
  for (long long i = 0; i < (long long)n; i++) {
    cin >> P[i];
    is[P[i]] = 1;
  }
  for (long long i = 0; i < (long long)5001; i++) {
    Re2[i * (i - 1) / 2] = i;
  }
  sort(P.begin(), P.end());
  for (long long i = 0; i < (long long)n; i++) {
    bool ok = 0;
    ti++;
    for (long long j = 0; j < (long long)i; j++) {
      int c = -P[j] + P[i];
      B[c]++;
    }
  }
  for (long long i = (long long)1; i < (long long)dd; i++) {
    int g = 0;
    for (int j = 1; j * i < dd; j++) {
      g += B[i * j];
    }
    if (g > k * (k + 1) / 2) {
      continue;
    }
    int kk = k;
    ts++;
    for (long long j = 0; j < (long long)n; j++) {
      int t = P[j] % i;
      if (Tl[t] != ts) L[t] = 0, Tl[t] = ts;
      L[t]++;
      if (L[t] > 1) kk--;
      if (kk < 0) break;
    }
    if (kk >= 0) {
      cout << i;
      return 0;
    }
  }
}
