#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-8;
const double PI = acos(-1);
const int N = 1000001;
int f1[N];
int f2[N];
int a[5000];
vector<int> p[N];
int main() {
  int n, k;
  while (cin >> n >> k) {
    for (int i = 0; i < (int)n; ++i) {
      scanf("%d", a + i);
    }
    if (n <= k + 1) {
      cout << 1 << endl;
      continue;
    }
    for (int j = 0; j < (int)n; ++j)
      for (int i = 0; i < (int)j; ++i) {
        int d = abs(a[i] - a[j]);
        if (p[d].size() < 2 * (k + 1)) {
          p[d].push_back(a[i]);
          p[d].push_back(a[j]);
        }
      }
    for (int m = n - k;; ++m) {
      int cnt = 0;
      for (int i = m; i < N; i += m) {
        if (p[i].size() >= 2 * (k + 1)) {
          cnt = k + 1;
          break;
        }
        for (__typeof((p[i]).begin()) it = (p[i]).begin(); it != (p[i]).end();
             ++it) {
          if (f1[*it] == m) continue;
          f1[*it] = m;
          int a = *it % m;
          if (f2[a] == m)
            cnt++;
          else
            f2[a] = m;
        }
        if (cnt > k) break;
      }
      if (cnt <= k) {
        cout << m << endl;
        break;
      }
    }
  }
}
