#include <bits/stdc++.h>
using namespace std;
int a[5005], c[1000005], n;
bool used[1000005];
int main() {
  int i, j, k, m;
  while (~scanf("%d%d", &n, &k)) {
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    memset(c, 0, sizeof(c));
    for (i = 1; i < n; i++)
      for (j = i; j <= n; j++) c[a[j] - a[i]]++;
    for (i = 1; i <= a[n] + 1; i++) {
      m = 0;
      for (j = i; j <= 1000000; j += i) {
        m += c[j];
        if (m > k * (k + 1) / 2) goto A;
      }
      memset(used, false, sizeof(used));
      m = 0;
      for (j = 1; j <= n; j++) {
        if (used[a[j] % i]) m++;
        used[a[j] % i] = true;
        if (m > k) goto A;
      }
      break;
    A:;
    }
    printf("%d\n", i);
  }
  return 0;
}
