#include <bits/stdc++.h>
using namespace std;
int n, k;
int v[5010];
int cnt[1000010];
int tot[1000010];
int q[5010];
int siz;
bool check(int t) {
  siz = 0;
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    tot[v[i] % t]++;
    q[siz++] = v[i] % t;
    if (tot[v[i] % t] > 1) tmp++;
    if (tmp > k) {
      for (int j = 0; j < siz; j++) tot[q[j]] = 0;
      return false;
    }
  }
  for (int j = 0; j < siz; j++) tot[q[j]] = 0;
  return true;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%d", v + i);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) cnt[abs(v[i] - v[j])]++;
  }
  for (int i = 1; i <= 1000001; i++) {
    int tmp = 0;
    for (int j = i; j <= 1000000; j += i) {
      tmp += cnt[j];
      if (tmp > k * (k + 1) / 2) break;
    }
    if (tmp > k * (k + 1) / 2) continue;
    if (check(i)) {
      cout << i;
      break;
    }
  }
  return 0;
}
