#include <bits/stdc++.h>
using namespace std;
int n, k;
int Mxof, Mnof;
int f[1234567];
int Vis[1234567];
int a[5678];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    Mxof = max(Mxof, a[i]);
    Mnof = min(Mnof, a[i]);
    for (int j = 1; j < i; ++j) ++f[abs(a[i] - a[j])];
  }
  register int Range = Mxof - Mnof;
  Mxof++;
  for (register int m = 1; m <= Mxof; ++m) {
    register int Sumof = 0;
    for (register int i = 0; i <= Range; i += m) {
      Sumof += f[i];
      if (Sumof > k * (k + 1) / 2) break;
    }
    if (Sumof <= k * (k + 1) / 2) {
      register int cnt = 0;
      for (register int i = 1; i <= n; ++i)
        if (Vis[a[i] % m]++) cnt++;
      if (cnt <= k) {
        printf("%d\n", m);
        return 0;
      }
      for (int i = 1; i <= n; --Vis[a[i++] % m])
        ;
    }
  }
  return 0;
}
