#include <bits/stdc++.h>
using namespace std;
int n, most;
int x[5001];
int rem[1000001];
vector<int> factors[1000001];
int fbdCnt[1000001];
int realCnt[1000001];
int limit[] = {0, 1, 3, 6, 10};
bool check(int mod) {
  if (realCnt[mod] > limit[most]) return false;
  int bad = 0;
  int mostI = -1;
  for (int i = 0; i < n; i++) {
    int t = x[i] % mod;
    rem[t]++;
    if (rem[t] > 1) bad++;
    if (bad > most) {
      mostI = i;
      break;
    }
  }
  for (int i = 0; i <= mostI; i++) {
    int t = x[i] % mod;
    rem[t]--;
  }
  return (bad <= most);
}
int MAIN() {
  while (cin >> n >> most) {
    memset(rem, 0, sizeof(rem));
    for (int i = 0; i < n; i++) cin >> x[i];
    memset(fbdCnt, 0, sizeof(fbdCnt));
    memset(realCnt, 0, sizeof(realCnt));
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        int t = abs(x[i] - x[j]);
        fbdCnt[t]++;
      }
    for (int i = 1; i <= 1000000; i++) realCnt[i] += fbdCnt[0];
    for (int i = 1; i <= 1000000; i++)
      for (int j = i; j <= 1000000; j += i) realCnt[i] += fbdCnt[j];
    for (int i = n - most;; i++)
      if (check(i)) {
        cout << i << endl;
        break;
      }
  }
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  return MAIN();
}
