#include <bits/stdc++.h>
using namespace std;
int v[5005];
int mod[1001010];
int quan[1001010];
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  int kk = (k + 1) * k / 2;
  for (int i = 0; i < n; i++) scanf("%d", v + i);
  sort(v, v + n);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      quan[abs(v[i] - v[j])]++;
    }
  }
  int sum, cont;
  for (int i = n - k; i <= v[n - 1] + 1; i++) {
    sum = 0;
    for (int j = i; j < v[n - 1]; j += i) {
      sum += quan[j];
      if (sum > kk) break;
    }
    if (sum > kk) continue;
    cont = 0;
    memset(mod, 0, sizeof(mod));
    for (int m = 0; m < n; m++) {
      int lol = v[m] % i;
      if (!mod[lol])
        mod[lol]++;
      else {
        cont++;
        if (cont > k) break;
      }
    }
    if (cont > k)
      continue;
    else {
      printf("%d", i);
      return 0;
    }
  }
}
