#include <bits/stdc++.h>
const int M = 1000001;
const int N = 5001;
int re[M], num[M], a[N];
int abs(int x) { return x > 0 ? x : -x; }
int main() {
  int n, k, i, j;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (i = 0; i < n; i++)
    for (j = i + 1; j < n; j++) {
      num[abs(a[i] - a[j])]++;
    }
  for (i = n - k;; i++) {
    int t = 0;
    for (j = i; j < M; j += i) {
      t += num[j];
    }
    if (t > k * (k + 1) / 2) {
      continue;
    }
    int v = 0;
    for (j = 0; j < n; j++) {
      if (re[a[j] % i] == i) {
        v++;
      }
      re[a[j] % i] = i;
    }
    if (v <= k) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}
