#include <bits/stdc++.h>
using namespace std;
int vet[5010], rnd, us[1000005], id[1000005], h[1000005], t[1000005];
pair<int, int> diff[1000005][10];
int find(int x) {
  if (id[x] == x) return x;
  return id[x] = find(id[x]);
}
void join(int x, int y) {
  if (h[x] > h[y])
    id[y] = x;
  else
    id[x] = y;
  if (h[x] == h[y]) h[y]++;
  return;
}
int main() {
  int n, k, M = 0, ans, cnt;
  bool can;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &vet[i]);
    M = max(M, vet[i]);
    for (int j = 0; j < i; j++) {
      int d = abs(vet[i] - vet[j]);
      if (t[d] < 2 * k + 1) diff[d][t[d]++] = (pair<int, int>(vet[i], vet[j]));
    }
  }
  ans = M + 1;
  rnd = 0;
  for (int m = 1; m <= M; m++) {
    ++rnd;
    can = true;
    cnt = 0;
    for (int i = m; can && i <= M; i += m) {
      for (int j = 0; j < t[i]; j++) {
        int u, v;
        u = diff[i][j].first;
        v = diff[i][j].second;
        if (us[u] != rnd) {
          us[u] = rnd;
          id[u] = u;
          h[u] = 1;
        }
        if (us[v] != rnd) {
          us[v] = rnd;
          id[v] = v;
          h[v] = 1;
        }
        u = find(u);
        v = find(v);
        if (u != v) {
          cnt++;
          join(u, v);
        }
        if (cnt > k) {
          can = false;
          break;
        }
      }
    }
    if (can) {
      ans = m;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
