#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
const int MAXV = 1.1e6;
const int V = 1e6 + 10;
int N, K;
int A[MAXN];
int cnts[MAXV];
bool vis[MAXV];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      cnts[abs(A[i] - A[j])]++;
    }
  }
  for (int v = 1; v <= V; v++) {
    int pairs = 0;
    for (int g = v; g <= V; g += v) {
      pairs += cnts[g];
    }
    if (pairs > K * (K + 1) / 2) continue;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (vis[A[i] % v]) {
        cnt++;
        if (cnt > K) {
          for (int j = 0; j < i; j++) {
            vis[A[j] % v] = false;
          }
          goto failed;
        }
      } else {
        vis[A[i] % v] = true;
      }
    }
    cout << v << '\n';
    exit(0);
  failed:;
  }
  assert(false);
  return 0;
}
