#include <bits/stdc++.h>
using namespace std;
const int maxN = 5000 + 2;
const int maxV = 1000000 + 2;
int N, K;
int A[maxN];
int D[maxV];
bool sgn[maxN];
int main() {
  while (scanf("%d %d", &N, &K) == 2) {
    int i;
    for (i = 0; i < N; i++) scanf("%d", A + i);
    int Max = A[0];
    for (i = 1; i < N; i++) {
      if (Max < A[i]) {
        Max = A[i];
      }
    }
    memset(D, 0, (Max + 1) * sizeof(int));
    int diff;
    int j;
    for (i = 0; i < N; i++) {
      for (j = i + 1; j < N; j++) {
        diff = A[i] - A[j];
        if (diff < 0) diff = -diff;
        D[diff]++;
      }
    }
    int down = max(1, min(N, Max) - K), up = max(1, max(N, Max) - K);
    int sum;
    for (i = down; i <= up; i++) {
      sum = 0;
      for (j = i; j < Max; j += i) {
        sum += D[j];
        if ((sum << 1) > K * (K + 1)) break;
      }
      if ((sum << 1) > K * (K + 1)) continue;
      for (j = 0; j < i; j++) sgn[j] = 0;
      sum = 0;
      for (j = 0; j < N; j++) {
        if (sgn[A[j] % i])
          sum++;
        else
          sgn[A[j] % i] = 1;
      }
      if (sum <= K) {
        printf("%d\n", i);
        break;
      }
    }
  }
  return 0;
}
