#include <bits/stdc++.h>
using namespace std;
const int N = 5009;
const int M = 1e6 + 9;
int a[M];
int ar[N];
bool on[M];
int main() {
  int n, lim;
  cin >> n >> lim;
  for (int i = 0; i < n; i++) cin >> ar[i];
  sort(ar, ar + n);
  int ma = -1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      a[ar[j] - ar[i]]++;
      ma = max(ma, ar[j] - a[i]);
    }
  }
  for (int i = max(1, n - lim);; i++) {
    int cnt = 0;
    for (int j = i; j <= ma; j += i) cnt += a[j];
    if (cnt > lim * (lim + 1) / 2) continue;
    memset(on, 0, sizeof(on));
    cnt = 0;
    for (int j = 0; j < n; j++)
      if (on[ar[j] % i]) {
        cnt++;
        if (cnt > lim) break;
      } else
        on[ar[j] % i] = 1;
    if (cnt <= lim) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
