#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 30000020;
int bufpos;
char buf[MAXSIZE];
void init() {
  buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
  bufpos = 0;
}
int readint() {
  int val = 0;
  for (; !isdigit(buf[bufpos]); bufpos++)
    ;
  for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] - '0';
  return val;
}
char readchar() {
  for (; isspace(buf[bufpos]); bufpos++)
    ;
  return buf[bufpos++];
}
int readstr(char* s) {
  int cur = 0;
  for (; isspace(buf[bufpos]); bufpos++)
    ;
  for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos];
  s[cur] = '\0';
  return cur;
}
int cnt[1000002];
int a[5001];
int qwq[1000002];
int main() {
  init();
  int n = readint(), k = readint(), mmax = 0;
  for (int i = 1; i <= n; i++) mmax = max(mmax, a[i] = readint());
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < i; j++) cnt[a[i] - a[j]]++;
  for (int i = max(1, n - k); i <= mmax + 1; i++) {
    int sum = 0;
    for (int j = i; j <= mmax; j += i) sum += cnt[j];
    if (sum > k * (k + 1) / 2) continue;
    int ans = 0;
    for (int j = 1; j <= n; j++) {
      if (qwq[a[j] % i]) ans++;
      qwq[a[j] % i]++;
    }
    if (ans <= k) {
      printf("%d\n", i);
      return 0;
    }
    for (int j = 1; j <= n; j++) qwq[a[j] % i] = 0;
  }
}
