#include <bits/stdc++.h>
using namespace std;
int num[1001000], flag[1001000];
int main() {
  int n, k, a[5010];
  scanf("%d %d", &n, &k);
  int maxn = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > maxn) maxn = a[i];
  }
  memset(num, 0, sizeof(num));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) num[abs(a[i] - a[j])]++;
  }
  for (int i = n - k; i <= maxn + 1; i++) {
    int sum = 0;
    for (int j = i; j <= maxn + 1; j += i) {
      sum += num[j];
      if (sum > k * (k + 1) / 2) break;
    }
    if (sum > k * (k + 1) / 2) continue;
    memset(flag, 0, sizeof(flag));
    int cnt = 0, sign = 0;
    for (int j = 0; j < n; j++) {
      int x = a[j] % i;
      if (!flag[x])
        flag[x] = 1;
      else {
        cnt++;
        if (cnt > k) {
          sign = 1;
          break;
        }
      }
    }
    if (sign == 0) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}
