#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(int o) {
  int b = mod, u = 0, v = 1, t, a=o;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += mod;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    int arr[n+5];
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            temp=abs(arr[i]-arr[j]);
            if(diff[temp].size()<2 * (k + 1))
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(i,1,1000002)
    {
        vi val;
        int rem=0;
        for(int u=0; u<1000001; u+=i)
        {
            if(diff[u].size()>= 2*(k + 1))    { rem=k+1; break; }
            forr(x,diff[u])
            {
                if(used[x]) continue;
                temp=x%i;
                if(taken[temp])
                    rem++;
                else taken[temp]=true;
                used[x]=true;
                val.pb(x);
            }
            if(rem>k) break;
        }
        if(rem<=k)
        {
            cout<<i<<endl;
            return ;
        }
        forr(x,val)
        {
            used[x]=false;
            taken[x%i]=false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    vi arr(n+5);
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            temp=abs(arr[i]-arr[j]);
            if(diff[temp].size()<=2*k)
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return ;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    vi arr(n+5);
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            temp=aabs(arr[i]-arr[j]);
            if(diff[temp].size()<=2*k)
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return ;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FORE(i,c) for(__typeof(c.begin()) i=(c.begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SZ(x) (int)(x).size()
#define ALL(c) c.begin(),c.end()
#define ZERO(x) memset(x,0,sizeof(x))

vector<int> df[1000005];

bool taken[1000005];
bool used[1000005];

int main() {
    mran
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i <= 1000000; ++i) {
        df[i].reserve(10);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (i != j) {
                int c = abs(v[i] - v[j]);
                if ((int) df[c].size() < 2 * (k + 1)) {
                    df[c].PB(v[i]);
                    df[c].PB(v[j]);
                }
            }
        }
    }
    for (int m = 1; m <= 1000001; ++m) {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) df[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            FORE (it, df[d]) {
                if (used[*it]) {
                    continue;
                }
                int a = *it % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[*it] = true;
                cused.PB(*it);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return 0;
        }
        FORE (it, cused) {
            used[*it] = false;
            taken[*it % m] = false;
        }
    }
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(__typeof(arr.begin()) x=(arr.begin()) ; x!=(arr.end()) ; ++x)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(int o) {
  int b = mod, u = 0, v = 1, t, a=o;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += mod;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    int arr[n+5];
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            temp=aabs(arr[i]-arr[j]);
            if(diff[temp].size()<=2*k)
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(i,2,1000002)
    {
        vi val;
        int rem=0;
        for(int u=0; u<1000001; u+=i)
        {
            if(diff[u].size()> 2*k)    { rem=k+1; break; }
            forr(x,diff[u])
            {
                if(used[*x]) continue;
                temp=*x%i;
                if(taken[temp])
                    rem++;
                else taken[temp]=true;
                used[*x]=true;
                val.pb(*x);
            }
            if(rem>k) break;
        }
        if(rem<=k)
        {
            cout<<i<<endl;
            return ;
        }
        forr(x,val)
        {
            used[*x]=false;
            taken[*x%i]=false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(int o) {
  int b = mod, u = 0, v = 1, t, a=o;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += mod;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{

}

int main()
{
    fastio
    int t=1;
    //cin>>t;

     int n, k, temp;
    cin>>n>>k;
    int arr[n+5];
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return 0;}
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            temp=aabs(arr[i]-arr[j]);
            if(diff[temp].size()<=2*k)
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return 0;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }

    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(int o) {
  int b = mod, u = 0, v = 1, t, a=o;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += mod;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    int arr[n+5];
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            temp=aabs(arr[i]-arr[j]);
            if(diff[temp].size()<2 * (k + 1))
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(i,1,1000002)
    {
        vi val;
        int rem=0;
        for(int u=0; u<1000001; u+=i)
        {
            if(diff[u].size()>= 2*(k + 1))    { rem=k+1; break; }
            forr(x,diff[u])
            {
                if(used[x]) continue;
                temp=x%i;
                if(taken[temp])
                    rem++;
                else taken[temp]=true;
                used[x]=true;
                val.pb(x);
            }
            if(rem>k) break;
        }
        if(rem<=k)
        {
            cout<<i<<endl;
            return ;
        }
        forr(x,val)
        {
            used[x]=false;
            taken[x%i]=false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(int o) {
  int b = mod, u = 0, v = 1, t, a=o;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += mod;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

bool exis[1000010];
vi diff[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    int arr[n+5];
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    fol(i,0,n)
    {
        fol(j,0,n)
        {
            if(i==j) continue;
            temp=aabs(arr[i]-arr[j]);
            exis[temp]=true;
            if(diff[temp].size()<=(2*k))
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(i,2,1000002)
    {
        set<int> used, remainder;
        int rem=0;
        for(int u=i; u<1000001; u+=i)
        {
            if(diff[u].size()>(2*k))    { rem=k+1; break; }
            forr(x,diff[u])
            {
                if(used.find(x)!=used.end()) continue;
                temp=x%u;
                if(remainder.find(temp)!=remainder.end())
                    rem++;
                else remainder.insert(temp);
                used.insert(x);
            }
            if(rem>k) break;
        }
        if(rem<=k)
        {
            cout<<i<<endl;
            return ;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    if((n-1)<=k) {cout<<1<<endl; return;}
    for (int i = 0; i <= 1000000; ++i) {
        diff[i].reserve(10);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (i != j) {
                int c = abs(v[i] - v[j]);
                if ((int) diff[c].size() < 2 * (k + 1)) {
                    diff[c].pb(v[i]);
                    diff[c].pb(v[j]);
                }
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return ;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i <= 1000000; ++i) {
        diff[i].reserve(10);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (i != j) {
                int c = abs(v[i] - v[j]);
                if ((int) diff[c].size() < 2 * (k + 1)) {
                    diff[c].pb(v[i]);
                    diff[c].pb(v[j]);
                }
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return ;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    vi arr(n+5);
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}

    for (int i = 0; i <= 1000000; ++i) {
        diff[i].reserve(10);
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            int c = abs(v[i] - v[j]);
            if(diff[c].size()<=2*k)
            {
                diff[c].pb(arr[i]);
                diff[c].pb(arr[j]);
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return ;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(int o) {
  int b = mod, u = 0, v = 1, t, a=o;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += mod;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

vi diff[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    int arr[n+5];
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            temp=aabs(arr[i]-arr[j]);
            if(diff[temp].size()<=(2*k))
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(i,2,20)
    {
        set<int> used, remainder;
        int rem=0;
        for(int u=i; u<20; u+=i)
        {
            if(diff[u].size()>(2*k))    { rem=k+1; break; }
            forr(x,diff[u])
            {
                if(used.find(x)!=used.end()) continue;
                temp=x%u;
                if(remainder.find(temp)!=remainder.end())
                    rem++;
                else remainder.insert(temp);
                used.insert(x);
            }
            cout<<endl;
            if(rem>k) break;
        }
        if(rem<=k)
        {
            cout<<i<<endl;
            return ;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    vi arr(n+5);
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}

    for (int i = 0; i <= 1000000; ++i) {
        diff[i].reserve(10);
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            temp=abs(arr[i]-arr[j]);
            if(diff[temp].size()<=2*k)
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return ;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(int o) {
  int b = mod, u = 0, v = 1, t, a=o;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += mod;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    int arr[n+5];
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            temp=aabs(arr[i]-arr[j]);
            if(diff[temp].size()<=2*k)
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return ;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#define ll long long
#define P pair<int,int>
#define Pll pair<long,long>
#define rson mid+1,r,rt<<1|1
#define lson l,mid,rt<<1
#define maxn 6000
using namespace std;

int a[maxn],num[1000010];
int n,k,maxa;
bool bo[1000010];

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        maxa=max(maxa,a[i]);
    }
    sort(a,a+n);

    for(int i=1;i<n;i++)
        for(int j=0;j<i;j++)
            num[a[i]-a[j]]++;

    for(int m=1;m<=maxa+1;m++)
    {
        ll sum=0;
        for(int i=m;i<=maxa+1;i+=m)
        {
            sum+=num[i];
            if(sum>k*(k+1)/2)
                break;
        }
        if(sum>k*(k+1)/2)
            continue;

        int cn=0,flag=1;
        for(int j=0;j<n&&flag;j++)
        {
            int mod=a[j]%m;
            if(!bo[mod])
                bo[mod]=1;
            else
            {
                cn++;
                if(cn>k)
                    flag=0;
            }
        }
        if(flag)
        {
            printf("%d\n",m);
            break;
        }
        for(int f=0;f<n;f++)
            bo[a[f]%m]=0;

    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%I64d",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod int(1e9+7)
#define lc (d<<1)
#define rc (d<<1|1)
#define P pair<int,int>
#define pi acos(-1)
int n,k,a[5008],b[1000008],d[10];
set<int>c[1000008],tt;
int main()
{
    cin.tie(0);
    while(si(n)!=EOF)
    {
        si(k);
        int s=1;
        FOR(i,1,n)
        {
            si(a[i]);
        }
        REW(b,0);
        FOR(i,1,n)
        {
            FOR(j,i+1,n)
            {
                int x=a[i],y=a[j];
                if(x<y)
                {
                    swap(x,y);
                }
                b[x-y]++;
                c[x-y].insert(x),c[x-y].insert(y);
            }
        }
        int z=*max_element(a+1,a+n+1);
        FOR(i,1,z+1)
        {
            int np=0;
            for(int j=i;j<=z+1;j+=i)
            {
                set<int>::iterator it=c[j].begin();
                while(it!=c[j].end())
                {
                    tt.insert(*it);
                    ++it;
                }
                np=tt.size();
                if(np>2*k)
                {
                    break;
                }
            }
            set<int>::iterator it=tt.begin();
            int zz=0,pp=0;
            while(it!=tt.end())
            {
                d[zz++]=*it%i;
                ++it;
            }
            tt.clear();
            if(np>2*k)
            {
                continue;
            }
            FOR(j,0,zz-1)
            {
                if(d[j]!=inf)
                {
                    FOR(kk,j+1,zz-1)
                    {
                        if(d[j]==d[kk])
                        {
                            pp++;
                            d[kk]=inf;
                        }
                    }
                }
            }
            if(pp<=k)
            {
                s=i;
                break;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%I64d",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod int(1e9+7)
#define lc (d<<1)
#define rc (d<<1|1)
#define P pair<int,int>
#define pi acos(-1)
int n,k,a[5008],b[1000008];
int main()
{
    cin.tie(0);
    while(si(n)!=EOF)
    {
        si(k);
        int s=1;
        FOR(i,1,n)
        {
            si(a[i]);
        }
        REW(b,0);
        FOR(i,1,n)
        {
            FOR(j,i+1,n)
            {
                int x=a[i],y=a[j];
                if(x<y)
                {
                    swap(x,y);
                }
                b[x-y]++;
            }
        }
        int z=*max_element(a+1,a+n+1);
        FOR(i,1,z+1)
        {
            int np=0;
            for(int j=i;j<=z+1;j+=i)
            {
                np+=b[j];
                if(np>k*(k+1)/2)
                {
                    break;
                }
            }
            if(np>k*(k+1)/2)
            {
                continue;
            }
            s=i;
            break;
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%I64d",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod int(1e9+7)
#define lc (d<<1)
#define rc (d<<1|1)
#define P pair<int,int>
#define pi acos(-1)
int n,k,a[5008],b[1000008],d[1000008];
set<int>c[1000008],tt;
vector<int>q;
int main()
{
    cin.tie(0);
    while(si(n)!=EOF)
    {
        si(k);
        int s=1;
        FOR(i,1,n)
        {
            si(a[i]);
        }
        REW(b,0);
        FOR(i,1,n)
        {
            FOR(j,i+1,n)
            {
                int x=a[i],y=a[j];
                if(x<y)
                {
                    swap(x,y);
                }
                b[x-y]++;
                c[x-y].insert(x),c[x-y].insert(y);
            }
        }
        int z=*max_element(a+1,a+n+1);
        FOR(i,1,z+1)
        {
            int nc=0;
            for(int j=i;j<=z+1;j+=i)
            {
                nc+=b[j];
                q.push_back(j);
                if(nc>k*(k+1)/2)
                {
                    break;
                }
            }
            if(nc>k*(k+1)/2)
            {
                q.clear();
                continue;
            }
            int pp=0;
            for(auto it=q.begin();it!=q.end();it++)
            {
                for(auto its=c[*it].begin();its!=c[*it].end();its++)
                {
                    tt.insert(*its);
                }
            }
            q.clear();
            REW(d,0);
            for(auto it=tt.begin();it!=tt.end();it++)
            {
                if(d[*it%i])
                {
                    pp++;
                }
                else
                {
                    d[*it%i]++;
                }
            }
            if(pp<=k)
            {
                s=i;
                break;
            }
            tt.clear();
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%I64d",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod int(1e9+7)
#define lc (d<<1)
#define rc (d<<1|1)
#define P pair<int,int>
#define pi acos(-1)
int n,k,a[5008],b[1000008],d[10];
set<int>c[1000008],tt;
int main()
{
    cin.tie(0);
    while(si(n)!=EOF)
    {
        si(k);
        int s=1;
        FOR(i,1,n)
        {
            si(a[i]);
        }
        REW(b,0);
        FOR(i,1,n)
        {
            FOR(j,i+1,n)
            {
                int x=a[i],y=a[j];
                if(x<y)
                {
                    swap(x,y);
                }
                b[x-y]++;
                c[x-y].insert(x),c[x-y].insert(y);
            }
        }
        int z=*max_element(a+1,a+n+1);
        FOR(i,1,z+1)
        {
            int np=0,nc=0;
            for(int j=i;j<=z+1;j+=i)
            {
                set<int>::iterator it=c[j].begin();
                while(it!=c[j].end())
                {
                    tt.insert(*it);
                    ++it;
                }
                nc+=b[j];
                np=tt.size();
                if(nc>k*(k+1)/2)
                {
                    break;
                }
            }
            if(nc>k*(k+1)/2)
            {
                continue;
            }
            set<int>::iterator it=tt.begin();
            int zz=0,pp=0;
            while(it!=tt.end())
            {
                d[zz++]=*it%i;
                ++it;
            }
            tt.clear();
            if(np>2*k)
            {
                continue;
            }
            FOR(j,0,zz-1)
            {
                if(d[j]!=inf)
                {
                    FOR(kk,j+1,zz-1)
                    {
                        if(d[j]==d[kk])
                        {
                            pp++;
                            d[kk]=inf;
                        }
                    }
                }
            }
            if(pp<=k)
            {
                s=i;
                break;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%I64d",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod int(1e9+7)
#define lc (d<<1)
#define rc (d<<1|1)
#define P pair<int,int>
#define pi acos(-1)
int n,k,a[5008],b[1000008];
set<int>c[1000008],tt;
int main()
{
    cin.tie(0);
    while(si(n)!=EOF)
    {
        si(k);
        int s=1;
        FOR(i,1,n)
        {
            si(a[i]);
        }
        REW(b,0);
        FOR(i,1,n)
        {
            FOR(j,i+1,n)
            {
                int x=a[i],y=a[j];
                if(x<y)
                {
                    swap(x,y);
                }
                b[x-y]++;
                c[x-y].insert(x),c[x-y].insert(y);
            }
        }
        int z=*max_element(a+1,a+n+1);
        FOR(i,1,z+1)
        {
            int np=0;
            for(int j=i;j<=z+1;j+=i)
            {
                set<int>::iterator it=c[j].begin();
                while(it!=c[j].end())
                {
                    tt.insert(*it);
                    ++it;
                }
                np=tt.size();
                if(np-1>k)
                {
                    break;
                }
            }
            tt.clear();
            if(np-1>k)
            {
                continue;
            }
            s=i;
            break;
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%I64d",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod int(1e9+7)
#define lc (d<<1)
#define rc (d<<1|1)
#define P pair<int,int>
#define pi acos(-1)
int n,k,a[5008],b[1000008],d[1000008];
int main()
{
    cin.tie(0);
    while(si(n)!=EOF)
    {
        si(k);
        int s=1;
        FOR(i,1,n)
        {
            si(a[i]);
        }
        REW(b,0);
        FOR(i,1,n)
        {
            FOR(j,i+1,n)
            {
                int x=a[i],y=a[j];
                if(x<y)
                {
                    swap(x,y);
                }
                b[x-y]++;
            }
        }
        int z=*max_element(a+1,a+n+1);
        FOR(i,1,z+1)
        {
            int np=0,nc=0;
            for(int j=i;j<=z+1;j+=i)
            {
                nc+=b[j];
                if(nc>k*(k+1)/2)
                {
                    break;
                }
            }
            if(nc>k*(k+1)/2)
            {
                continue;
            }
            int pp=0;
            REW(d,0);
            FOR(j,1,n)
            {
                if(d[a[j]%i])
                {
                    pp++;
                }
                else
                {
                    d[a[j]%i]++;
                }
            }
            if(pp<=k)
            {
                s=i;
                break;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%I64d",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod int(1e9+7)
#define lc (d<<1)
#define rc (d<<1|1)
#define P pair<int,int>
#define pi acos(-1)
int n,k,a[5008],b[1000008],d[10];
set<int>c[1000008],tt;
int main()
{
    cin.tie(0);
    while(si(n)!=EOF)
    {
        si(k);
        int s=1;
        FOR(i,1,n)
        {
            si(a[i]);
        }
        REW(b,0);
        FOR(i,1,n)
        {
            FOR(j,i+1,n)
            {
                int x=a[i],y=a[j];
                if(x<y)
                {
                    swap(x,y);
                }
                b[x-y]++;
                c[x-y].insert(x),c[x-y].insert(y);
            }
        }
        int z=*max_element(a+1,a+n+1);
        FOR(i,1,z+1)
        {
            int np=0,nc=0;
            for(int j=i;j<=z+1;j+=i)
            {
                set<int>::iterator it=c[j].begin();
                while(it!=c[j].end())
                {
                    tt.insert(*it);
                    ++it;
                }
                nc+=b[j];
                np=tt.size();
                if(nc>k*(k+1)/2||np>2*k)
                {
                    break;
                }
            }
            if(nc>k*(k+1)/2||np>2*k)
            {
                tt.clear();
                continue;
            }
            set<int>::iterator it=tt.begin();
            int zz=0,pp=0;
            while(it!=tt.end())
            {
                d[zz++]=*it%i;
                ++it;
            }
            tt.clear();
            FOR(j,0,zz-1)
            {
                if(d[j]!=inf)
                {
                    FOR(kk,j+1,zz-1)
                    {
                        if(d[j]==d[kk])
                        {
                            pp++;
                            d[kk]=inf;
                        }
                    }
                }
            }
            if(pp<=k)
            {
                s=i;
                break;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


#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;

		for (int i = 0; i < N; i++) {
			if (vis[A[i] % v]) {
				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;
}


#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;

		for (int i = 0; i < N; i++) {
			if (vis[A[i] % v]) {
				for (int j = 0; j < i; j++) {
					vis[A[j] % v] = false;
				}
				goto failed;
			}
		}
		cout << v << '\n';
		exit(0);
failed:
		;
	}
	assert(false);

	return 0;
}


#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;
}


#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  const int D = 1e6 + 10;
  int n, k;
  cin >> n >> k;
  vi a(n);
  for (int& elem: a) cin >> elem;
  vector <vi> arr(D);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      arr[abs(a[i] - a[j])].pb(a[i]);
      arr[abs(a[i] - a[j])].pb(a[j]);
    }
  }
  vector <bool> taken(D + 1, false);
  vector <bool> used(D + 1, false);
  for (int m = 1; m < D; m++) {
    vi rollback;
    int del = 0;
    for (int d = m; d < D; d += m) {
      if (arr[d].empty()) continue;
      if (sz(arr[d]) > 2 * k) {
        del = INT_MAX;
        break;
      }
      for (int ai: arr[d]) {
        if (used[ai]) continue;
        int aj = ai % m;
        if (taken[aj]) {
          del++;
        } else {
          taken[aj] = true;
        }
        used[ai] = true;
        rollback.pb(ai);
        if (del > k) break;
      }
    }
    if (del <= k) {
      cout << m << '\n';
      return (0);
    }
    for (int ai: rollback) {
      used[ai] = false;
      taken[ai % m] = false;
    }
  }
  return (0);
}


#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  const int D = 1e6 + 10;
  int n, k;
  cin >> n >> k;
  vi a(n);
  for (int& elem: a) cin >> elem;
  vector <vi> arr(D);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      arr[abs(a[i] - a[j])].pb(a[i]);
      arr[abs(a[i] - a[j])].pb(a[j]);
    }
  }
  vector <bool> taken(n + 1, false);
  vector <bool> used(n + 1, false);
  for (int m = 1; m < D; m++) {
    vi rollback;
    int del = 0;
    for (int d = m; d < D; d += m) {
      if (arr[d].empty()) continue;
      for (int ai: arr[d]) {
        if (used[ai]) continue;
        int aj = ai % m;
        if (taken[aj]) {
          del++;
        } else {
          taken[aj] = true;
        }
        used[ai] = true;
        rollback.pb(ai);
        if (del > k) break;
      }
    }
    if (del <= k) {
      cout << m << '\n';
      return (0);
    }
    for (int ai: rollback) {
      used[ai] = false;
      taken[ai % m] = false;
    }
  }
  return (0);
}


#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  const int D = 1e6 + 10;
  int n, k;
  cin >> n >> k;
  vi a(n);
  for (int& elem: a) cin >> elem;
  vector <vi> arr(D);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int dif = abs(a[i] - a[j]);
      if (sz(arr[dif]) > 2 * k) continue;
      arr[dif].pb(a[i]);
      arr[dif].pb(a[j]);
    }
  }
  vector <bool> taken(D + 1, false);
  vector <bool> used(D + 1, false);
  for (int m = 1; m < D; m++) {
    vi rollback;
    int del = 0;
    for (int d = m; d < D; d += m) {
      if (arr[d].empty()) continue;
      if (sz(arr[d]) > 2 * k) {
        del = INT_MAX;
        break;
      }
      for (int ai: arr[d]) {
        if (used[ai]) continue;
        int aj = ai % m;
        if (taken[aj]) {
          del++;
        } else {
          taken[aj] = true;
        }
        used[ai] = true;
        rollback.pb(ai);
        if (del > k) break;
      }
    }
    if (del <= k) {
      cout << m << '\n';
      return (0);
    }
    for (int ai: rollback) {
      used[ai] = false;
      taken[ai % m] = false;
    }
  }
  return (0);
}


#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  const int D = 1e6 + 10;
  int n, k;
  cin >> n >> k;
  vi a(n);
  for (int& elem: a) cin >> elem;
  vector <vi> arr(D);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      arr[abs(a[i] - a[j])].pb(a[i]);
      arr[abs(a[i] - a[j])].pb(a[j]);
    }
  }
  vector <bool> taken(D + 1, false);
  vector <bool> used(D + 1, false);
  for (int m = 1; m < D; m++) {
    vi rollback;
    int del = 0;
    for (int d = m; d < D; d += m) {
      if (arr[d].empty()) continue;
      for (int ai: arr[d]) {
        if (used[ai]) continue;
        int aj = ai % m;
        if (taken[aj]) {
          del++;
        } else {
          taken[aj] = true;
        }
        used[ai] = true;
        rollback.pb(ai);
        if (del > k) break;
      }
    }
    if (del <= k) {
      cout << m << '\n';
      return (0);
    }
    for (int ai: rollback) {
      used[ai] = false;
      taken[ai % m] = false;
    }
  }
  return (0);
}


#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<ctime>
#include<functional>
#include<algorithm>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int MX = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int A[MX], S[MX], vis[MX];
int main() {
    int n, k, Max = 0;
    scanf("%d%d", &n, &k);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &A[i]);
        Max = max(Max, A[i]);
    }

    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            S[abs(A[i] - A[j])]++;
        }
    }

    if(k >= n - 1) {
        printf("1\n");
        return 0;
    }

    int ans = 0;
    for(int i = n - k; i <= Max + 1; i++) {
        int cnt = 0, sign = false;
        for(int j = i; j <= Max + 1; j += i) {
            cnt += S[j];
            if(cnt > k * (k + 1) / 2) {
                sign = true;
                break;
            }
        }
        if(sign) continue;

        cnt = 0;
        sign = false;
        for(int j = 1; j <= n; j++) {
            if(vis[A[j] % i] != i) {
                vis[A[j] % i] = i;
            } else cnt++;
            if(cnt > k) {
                sign = true;
                break;
            }
        }
        if(sign) continue;

        ans = i;
        break;
    }

    printf("%d\n", ans);
    return 0;
}


#include <iostream>
#include <set>

using namespace std;

const int N = 1000001;

int f[N], a[N], k;

bool check(int n, int m) {
  set<int> b;
  int del = 0;
  for (int i = 1; i <= n && del <= k; ++i) {
    if (b.count(a[i] % m)) ++del;
    else b.insert(a[i] % m);
  }
  return del <= k;
}

int main() {
  int n;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    for (int j = 1; j < i; ++j) {
      int d = a[j] - a[i];
      if (d < 0) d = -d;
      f[d]++;
    }
  }
  for (int i = 1; i < N; ++i) {
    int count = 0;
    for (int j = 0; j < N; j += i) {
      count += f[j];
    }
    if (count <= k) {
      printf("%d", i);
      return 0;
    }
    if (count * 2 <= k * (k + 1) && check(n, i)) {
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}


#include <iostream>
#include <set>

using namespace std;

const int N = 1000001;

int f[N], a[N], k;

bool check(int n, int m) {
  set<int> b;
  int del = 0;
  for (int i = 1; i <= n && del <= k; ++i) {
    if (b.count(a[i] % m)) ++del;
    else b.insert(a[i] % m);
  }
  return del <= k;
}

int main() {
  int n;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    for (int j = 1; j < i; ++j) {
      int d = a[j] - a[i];
      if (d < 0) d = -d;
      f[d]++;
    }
  }
  for (int i = 1; i < N; ++i) {
    int count = 0;
    for (int j = 0; j < N; j += i) {
      count += f[j];
    }
    if (count * 2 <= k * (k + 1) && check(n, i)) {
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}


#include <iostream>
#include <unordered_set>

using namespace std;

const int N = 1000001;

int f[N], a[N], k;

bool check(int n, int m) {
  unordered_set<int> b;
  int del = 0;
  for (int i = 1; i <= n && del <= k; ++i) {
    if (b.count(a[i] % m)) ++del;
    else b.insert(a[i] % m);
  }
  return del <= k;
}

int main() {
  int n, maxDiff = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    for (int j = 1; j < i; ++j) {
      int d = a[j] - a[i];
      if (d < 0) d = -d;
      f[d]++;
      maxDiff = max(maxDiff, d);
    }
  }
  for (int i = 1; i < maxDiff; ++i) {
    int count = 0;
    bool ok = true;
    for (int j = i; j <= maxDiff; j += i) {
      count += f[j];
      if (count * 2 > k * (k + 1)) {
        ok = 0;
        break;
      }
    }
    if (!ok) continue;
    if (count <= k) {
      printf("%d", i);
      return 0;
    }
    if (check(n, i)) {
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}


#include <iostream>
#include <unordered_set>

using namespace std;

const int N = 1000001;

int f[N], a[N], k;

bool check(int n, int m) {
  unordered_set<int> b;
  int del = 0;
  for (int i = 1; i <= n && del <= k; ++i) {
    if (b.count(a[i] % m)) ++del;
    else b.insert(a[i] % m);
  }
  return del <= k;
}

int main() {
  int n, maxDiff = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    for (int j = 1; j < i; ++j) {
      int d = a[j] - a[i];
      if (d < 0) d = -d;
      f[d]++;
      maxDiff = max(maxDiff, d);
    }
  }
  if (n == 1) {
    puts("1");
    return 0;
  }
  for (int i = 1; i < maxDiff; ++i) {
    int count = 0;
    bool ok = true;
    for (int j = i; j <= maxDiff; j += i) {
      count += f[j];
      if (count * 2 > k * (k + 1)) {
        ok = 0;
        break;
      }
    }
    if (!ok) continue;
    if (count <= k) {
      printf("%d", i);
      return 0;
    }
    if (check(n, i)) {
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}


#include <iostream>
#include <unordered_set>

using namespace std;

const int N = 1000001;

int f[N], a[N], k;

bool check(int n, int m) {
  unordered_set<int> b;
  int del = 0;
  for (int i = 1; i <= n && del <= k; ++i) {
    if (b.count(a[i] % m)) ++del;
    else b.insert(a[i] % m);
  }
  return del <= k;
}

int main() {
  int n, maxDiff = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    for (int j = 1; j < i; ++j) {
      int d = a[j] - a[i];
      if (d < 0) d = -d;
      f[d]++;
      maxDiff = max(maxDiff, d);
    }
  }
  if (n == 1) {
    puts("1");
    return 0;
  }
  for (int i = 1; i < maxDiff; ++i) {
    int count = 0;
    bool ok = true;
    for (int j = i; j <= maxDiff; j += i) {
      count += f[j];
      if (count * 2 > k * (k + 1)) {
        ok = 0;
        break;
      }
    }
    if (!ok) continue;
    if (count <= k || check(n, i)) {
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}


#include <iostream>

using namespace std;

const int N = 1000001;

int f[N], a[N];

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    for (int j = 1; j < i; ++j) {
      int d = a[j] - a[i];
      if (d < 0) d = -d;
      f[d]++;
    }
  }
  for (int i = 1; i < N; ++i) {
    int count = 0;
    for (int j = 0; j < N; j += i) {
      count += f[j];
    }
    if (count <= k) {
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a)>(b)?(a):(b)
const int maxn=1e6+100;
int num[maxn];
int a[5500];
bool flag[maxn];
int dif(int a,int b){
   return  a>b? a-b:b-a;
}
int main(){
    int n,k,i,j,maxa,m,mark,sum,cn,mod;
    maxa=-1;
    while(scanf("%d%d",&n,&k)!=EOF){
        memset(num,0,sizeof(num));
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
            maxa=max(a[i],maxa);
        }
        //首先应知道a%m==b%m  -->  |a-b|%m==0
        for(i=1;i<n;i++){
            for(j=0;j<i;j++){
                //不同类型的同余对各有多少
                num[dif(a[i],a[j])]++;
            }
        }
        for(m=max(n-k,1);m<=maxa;m++){
            sum=0;
            for(i=m;i<=maxa;i+=m){
            //这里i+=m的原因是，这样能保证同余对 对于对之间也都是同余的，即这样挑出的组合中所有数都是同余的。
                sum+=num[i];        //
                if(sum>k*(k+1)/2){  //剪枝
                    break;
               }
            }
            if(sum>k*(k+1)/2){
                continue;
            }
            cn=0,mark=0;
            for(j=0;j<n&&(!mark);j++){  //暴力判断m是否满足题目的要求
                mod=a[j]%m;
                if(!flag[mod]){
                    flag[mod]=1;
                }else{
                    cn++;
                    if(cn>k){
                        mark=1;
                    }
                }
            }
            for(j=0;j<n;j++){   //还原
                flag[a[j]%m]=0;
            }
            if(!mark){
                mark=m;
                break;
            }
        }
        printf("%d\n",mark);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a)>(b)?(a):(b)
const int maxn=1e6+100;
int num[maxn];
int a[5500];
bool flag[maxn];
int dif(int a,int b){
   return  a>b? a-b:b-a;
}
int main(){
    int n,k,i,j,maxa,m,mark,sum,cn,mod;
    maxa=-1;
    while(scanf("%d%d",&n,&k)!=EOF){
        memset(num,0,sizeof(num));
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
            maxa=max(a[i],maxa);
        }
        //首先应知道a%m==b%m  -->  |a-b|%m==0
        for(i=1;i<n;i++){
            for(j=0;j<i;j++){
                //不同类型的同余对各有多少
                num[dif(a[i],a[j])]++;
            }
        }
        for(m=1;m<=maxa;m++){
            sum=0;
            for(i=m;i<=maxa;i+=m){
            //这里i+=m的原因是，这样能保证同余对 对于对之间也都是同余的，即这样挑出的组合中所有数都是同余的。
                sum+=num[i];        //
                //if(sum>k*(k+1)/2){  //剪枝
                    //break;
               // }
            }
            //if(sum>k*(k+1)/2){
                //continue;
            //}
            cn=0,mark=0;
            for(j=0;j<n&&(!mark);j++){  //暴力判断m是否满足题目的要求
                mod=a[j]%m;
                if(!flag[mod]){
                    flag[mod]=1;
                }else{
                    cn++;
                    if(cn>k){
                        mark=1;
                    }
                }
            }
            for(j=0;j<n;j++){   //还原
                flag[a[j]%m]=0;
            }
            if(!mark){
                mark=m;
                break;
            }
        }
        printf("%d\n",mark);
    }
    return 0;
}


#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 5e3 + 10;
const int A = 1e6 + 10;

typedef pair <int, int> II;

int n, m;
int a[N], diff[A];

bool Check(int mod) {
	vector <int> vertex;
	int op = 0;
	for (int i = mod; i < A; i += mod) {
		op += diff[i];
		if (op > m) return false;
	}
	return op <= m;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			diff[abs(a[i] - a[j])]++;
	for (int mod = 1; mod < A; ++mod) {
		if (Check(mod)) {
			cout << mod;
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 5e3 + 10;
const int A = 1e6 + 10;

typedef pair <int, int> II;

int n, m;
int a[N], diff[A];

bool Check(int mod) {
	vector <int> vertex;
	int op = 0;
	for (int i = mod; i < A; i += mod) {
		op += diff[i]
		if (op > m) return false;
	}
	return op <= m;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			diff[abs(a[i] - a[j])]++;
	DSU.Init(n);
	for (int mod = 1; mod < A; ++mod) {
		if (Check(mod)) {
			cout << mod;
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 5e3 + 10;
const int A = 1e6 + 10;

typedef pair <int, int> II;

int n, m;
int a[N];

struct DSU {
	int n;
	int p[N];
	void Init(int _n) {
		n = _n;
		for (int i = 1; i <= n; ++i) p[i] = -1;
	}
	int Root(int u) {
		return p[u] < 0 ? u : p[u] = Root(p[u]);
	}
	bool Union(int u, int v, vector <int> &V) {
		int ru = Root(u), rv = Root(v);
		if (ru == rv) return false;
		if (p[ru] > p[rv]) swap(ru, rv);
		p[ru] += p[rv];
		p[rv] = ru;
		V.push_back(u);
		V.push_back(v);
		return true;
	}
	void reset(vector <int> &vertex) {
		for (int v: vertex) p[v] = -1;
	}
} DSU;

vector <II> diff[A];

bool Check(int mod) {
	vector <int> vertex;
	int op = 0;
	for (int i = mod; i < A; i += mod) {
		for (II &x: diff[i]) {
			int u = x.first, v = x.second;
			op += DSU.Union(u, v, vertex);
			if (op > m) {
				// reset
				DSU.reset(vertex);
				return false;
			}
		}
	}
	DSU.reset(vertex);
	return op <= m;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j) {
			int d = abs(a[i] - a[j]);
			if (diff[d].size() < 4)
				diff[d].push_back(II(i, j));
		}
	DSU.Init(n);
	for (int mod = 1; mod < A; ++mod) {
		if (Check(mod)) {
			cout << mod;
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 5e3 + 10;
const int A = 1e6 + 10;

typedef pair <int, int> II;

int n, m;
int a[N];

struct DSU {
	int n;
	int p[N];
	void Init(int _n) {
		n = _n;
		for (int i = 1; i <= n; ++i) p[i] = -1;
	}
	int Root(int u) {
		return p[u] < 0 ? u : p[u] = Root(p[u]);
	}
	bool Union(int u, int v, vector <int> &V) {
		int ru = Root(u), rv = Root(v);
		if (ru == rv) return false;
		if (p[ru] > p[rv]) swap(ru, rv);
		p[ru] += p[rv];
		p[rv] = ru;
		V.push_back(u);
		V.push_back(v);
		return true;
	}
	void reset(vector <int> &vertex) {
		for (int v: vertex) p[v] = -1;
	}
} DSU;

vector <II> diff[A];

bool Check(int mod) {
	vector <int> vertex;
	int op = 0;
	for (int i = mod; i < A; i += mod) {
		for (II &x: diff[i]) {
			int u = x.first, v = x.second;
			op += DSU.Union(u, v, vertex);
			if (op > m) {
				// reset
				DSU.reset(vertex);
				return false;
			}
		}
	}
	DSU.reset(vertex);
	return op <= m;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j) {
			int d = abs(a[i] - a[j]);
			if (diff[d].size() < 6)
				diff[d].push_back(II(i, j));
		}
	DSU.Init(n);
	for (int mod = 1; mod < A; ++mod) {
		if (Check(mod)) {
			cout << mod;
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 5e3 + 10;
const int A = 1e6 + 10;

typedef pair <int, int> II;

int n, m;
int a[N];

struct DSU {
	int n;
	int p[N];
	void Init(int _n) {
		n = _n;
		for (int i = 1; i <= n; ++i) p[i] = -1;
	}
	int Root(int u) {
		return p[u] < 0 ? u : p[u] = Root(p[u]);
	}
	bool Union(int u, int v, vector <int> &V) {
		int ru = Root(u), rv = Root(v);
		if (ru == rv) return false;
		if (p[ru] > p[rv]) swap(ru, rv);
		p[ru] += p[rv];
		p[rv] = ru;
		V.push_back(u);
		V.push_back(v);
		return true;
	}
	void reset(vector <int> &vertex) {
		for (int v: vertex) p[v] = -1;
	}
} DSU;

vector <II> diff[A];

bool Check(int mod) {
	vector <int> vertex;
	int op = 0;
	for (int i = mod; i < A; i += mod) {
		for (II &x: diff[i]) {
			int u = x.first, v = x.second;
			op += DSU.Union(u, v, vertex);
			if (op > m) {
				// reset
				DSU.reset(vertex);
				return false;
			}
		}
	}
	DSU.reset(vertex);
	return op <= m;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j) {
			int d = abs(a[i] - a[j]);
			if (diff[d].size() < 5)
				diff[d].push_back(II(i, j));
		}
	DSU.Init(n);
	for (int mod = 1; mod < A; ++mod) {
		if (Check(mod)) {
			cout << mod;
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 5e3 + 10;
const int A = 1e6 + 10;

typedef pair <int, int> II;

int n, m;
int a[N];

struct DSU {
	int n;
	int p[N];
	void Init(int _n) {
		n = _n;
		for (int i = 1; i <= n; ++i) p[i] = -1;
	}
	int Root(int u) {
		return p[u] < 0 ? u : p[u] = Root(p[u]);
	}
	bool Union(int u, int v, vector <int> &V) {
		int ru = Root(u), rv = Root(v);
		if (ru == rv) return false;
		if (p[ru] > p[rv]) swap(ru, rv);
		p[ru] += p[rv];
		p[rv] = ru;
		V.push_back(u);
		V.push_back(v);
		return true;
	}
	void reset(vector <int> &vertex) {
		for (int v: vertex) p[v] = -1;
	}
} DSU;

vector <II> diff[A];

bool Check(int mod) {
	vector <int> vertex;
	int op = 0;
	for (int i = mod; i < A; i += mod) {
		for (II &x: diff[i]) {
			int u = x.first, v = x.second;
			op += DSU.Union(u, v, vertex);
			if (op > m) {
				// reset
				DSU.reset(vertex);
				return false;
			}
		}
	}
	DSU.reset(vertex);
	return op <= m;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			diff[abs(a[i] - a[j])].push_back(II(i, j));
	DSU.Init(n);
	for (int mod = 1; mod < A; ++mod) {
		if (Check(mod)) {
			cout << mod;
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 5e3 + 10;
const int A = 1e6 + 10;

typedef pair <int, int> II;

int n, m;
int a[N];

struct DSU {
	int n;
	int p[N];
	void Init(int _n) {
		n = _n;
		for (int i = 1; i <= n; ++i) p[i] = -1;
	}
	int Root(int u) {
		return p[u] < 0 ? u : p[u] = Root(p[u]);
	}
	bool Union(int u, int v, vector <int> &V) {
		int ru = Root(u), rv = Root(v);
		if (ru == rv) return false;
		if (p[ru] > p[rv]) swap(ru, rv);
		p[ru] += p[rv];
		p[rv] = ru;
		V.push_back(u);
		V.push_back(v);
		return true;
	}
	void reset(vector <int> &vertex) {
		for (int v: vertex) p[v] = -1;
	}
} DSU;

vector <II> diff[A];

bool Check(int mod) {
	vector <int> vertex;
	int op = 0;
	for (int i = mod; i < A; i += mod) {
		op += diff[i].size();
		if (op > m) return false;
	}
	return op <= m;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			diff[abs(a[i] - a[j])].push_back(II(i, j));
	DSU.Init(n);
	for (int mod = 1; mod < A; ++mod) {
		if (Check(mod)) {
			cout << mod;
			return 0;
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

struct para
{
    int a, b;
};

vector<int> Z;

void Stworz(int n)
{
    for (int i = 0; i < n; ++i)
        Z.push_back(i);
}

int Find(int a)
{
    if (Z[a] == a)
        return a;
    int fa = Find(Z[a]);
    Z[a] = fa;
    return fa;
}

int Union(int a, int b)
{
    int fa = Find(a);
    int fb = Find(b);
    if (fa != fb)
    {
        Z[fa] = fb;
        return 1;
    }
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector< vector<para> > pary(1000001);
    for (int i = 0; i < n; ++i)
    {
        for (int j = n - 1; j > i; --j)
        {
            int r = a[j] - a[i];
            if (r < n - k)
                break;
            if (pary[r].size() <= 6)
                pary[r].push_back({i, j});
        }
    }
    if (n == 5000)
        return 0;
    Stworz(n);
    vector<bool> jest(1000001, false);
    for (int i = max(1, n - k); i <= 1000000; ++i)
    {
        vector<int> rozne;
        bool ok = true;
        for (int j = i; j <= 1000000; j += i)
        {
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
            for (int l = 0; l < pary[j].size(); ++l)
            {
                if (!jest[pary[j][l].a])
                {
                    rozne.push_back(pary[j][l].a);
                    jest[pary[j][l].a] = true;
                }
                if (!jest[pary[j][l].b])
                {
                    rozne.push_back(pary[j][l].b);
                    jest[pary[j][l].b] = true;
                }
                if (rozne.size() > 8)
                    break;
            }
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
        {
            for (int j = 0; j < rozne.size(); ++j)
            {
                Z[rozne[j]] = rozne[j];
                jest[rozne[j]] = false;
            }
            continue;
        }
        int spojne = rozne.size();
        for (int j = i; j <= 1000000; j += i)
            for (int l = 0; l < pary[j].size(); ++l)
                spojne -= Union(pary[j][l].a, pary[j][l].b);
        if (rozne.size() - spojne <= k)
        {
            cout << i;
            return 0;
        }
        for (int j = 0; j < rozne.size(); ++j)
        {
            Z[rozne[j]] = rozne[j];
            jest[rozne[j]] = false;
        }
    }
}


#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

struct para
{
    int a, b;
};

vector<int> Z;

void Stworz(int n)
{
    for (int i = 0; i < n; ++i)
        Z.push_back(i);
}

int Find(int a)
{
    if (Z[a] == a)
        return a;
    int fa = Find(Z[a]);
    Z[a] = fa;
    return fa;
}

int Union(int a, int b)
{
    int fa = Find(a);
    int fb = Find(b);
    if (fa != fb)
    {
        Z[fa] = fb;
        return 1;
    }
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector< vector<para> > pary(1000001);
    for (int i = 0; i < n; ++i)
    {
        for (int j = n - 1; j > i; --j)
        {
            int r = a[j] - a[i];
            if (r < n - k)
                break;
            if (pary[r].size() <= 5)
                pary[r].push_back({i, j});
        }
    }
    Stworz(n);
    vector<bool> jest(1000001, false);
    for (int i = max(1, n - k); i <= 1000000; ++i)
    {
        vector<int> rozne;
        bool ok = true;
        for (int j = i; j <= 1000000; j += i)
        {
            if (pary[j].size() > 5)
            {
                ok = false;
                break;
            }
            for (int l = 0; l < pary[j].size(); ++l)
            {
                if (!jest[pary[j][l].a])
                {
                    rozne.push_back(pary[j][l].a);
                    jest[pary[j][l].a] = true;
                }
                if (!jest[pary[j][l].b])
                {
                    rozne.push_back(pary[j][l].b);
                    jest[pary[j][l].b] = true;
                }
                if (rozne.size() > 8)
                    break;
            }
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
        {
            for (int j = 0; j < rozne.size(); ++j)
            {
                Z[rozne[j]] = rozne[j];
                jest[rozne[j]] = false;
            }
            continue;
        }
        int spojne = rozne.size();
        for (int j = i; j <= 1000000; j += i)
            for (int l = 0; l < pary[j].size(); ++l)
                spojne -= Union(pary[j][l].a, pary[j][l].b);
        if (rozne.size() - spojne <= k)
        {
            cout << i;
            return 0;
        }
        for (int j = 0; j < rozne.size(); ++j)
        {
            Z[rozne[j]] = rozne[j];
            jest[rozne[j]] = false;
        }
    }
}


#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

struct para
{
    int a, b;
};

vector<int> Z;

void Stworz(int n)
{
    for (int i = 0; i < n; ++i)
        Z.push_back(i);
}

int Find(int a)
{
    if (Z[a] == a)
        return a;
    int fa = Find(Z[a]);
    Z[a] = fa;
    return fa;
}

int Union(int a, int b)
{
    int fa = Find(a);
    int fb = Find(b);
    if (fa != fb)
    {
        Z[fa] = fb;
        return 1;
    }
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector< vector<para> > pary(1000001);
    vector< unordered_set<int> > S(1000001);
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            int r = a[j] - a[i];
            if (S[r].size() <= 8)
            {
                pary[r].push_back({i, j});
                S[r].insert(i);
                S[r].insert(j);
            }
        }
    }
    Stworz(n);
    vector<bool> jest(1000001, false);
    for (int i = max(1, n - k); i <= 1000000; ++i)
    {
        vector<int> rozne;
        bool ok = true;
        for (int j = i; j <= 1000000; j += i)
        {
            if (S[j].size() > 8)
            {
                ok = false;
                break;
            }
            for (int l = 0; l < pary[j].size(); ++l)
            {
                if (!jest[pary[j][l].a])
                {
                    rozne.push_back(pary[j][l].a);
                    jest[pary[j][l].a] = true;
                }
                if (!jest[pary[j][l].b])
                {
                    rozne.push_back(pary[j][l].b);
                    jest[pary[j][l].b] = true;
                }
                if (rozne.size() > 8)
                    break;
            }
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
        {
            for (int j = 0; j < rozne.size(); ++j)
            {
                Z[rozne[j]] = rozne[j];
                jest[rozne[j]] = false;
            }
            continue;
        }
        int spojne = rozne.size();
        for (int j = i; j <= 1000000; j += i)
            for (int l = 0; l < pary[j].size(); ++l)
                spojne -= Union(pary[j][l].a, pary[j][l].b);
        if (rozne.size() - spojne <= k)
        {
            cout << i;
            return 0;
        }
        for (int j = 0; j < rozne.size(); ++j)
        {
            Z[rozne[j]] = rozne[j];
            jest[rozne[j]] = false;
        }
    }
}


#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

struct para
{
    int a, b;
};

vector<int> Z;

void Stworz(int n)
{
    for (int i = 0; i < n; ++i)
        Z.push_back(i);
}

int Find(int a)
{
    if (Z[a] == a)
        return a;
    int fa = Find(Z[a]);
    Z[a] = fa;
    return fa;
}

void Union(int a, int b)
{
    int fa = Find(a);
    int fb = Find(b);
    if (fa != fb)
        Z[fa] = fb;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector< vector<para> > pary(1000001);
    vector< unordered_set<int> > S(1000001);
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            int r = a[j] - a[i];
            if (S[r].size() <= 8)
            {
                pary[r].push_back({i, j});
                S[r].insert(i);
                S[r].insert(j);
            }
        }
    }
    Stworz(n);
    vector<bool> jest(1000001, false);
    for (int i = 1; i <= 1000000; ++i)
    {
        vector<int> rozne;
        vector<para> aktPary;
        bool ok = true;
        for (int j = i; j <= 1000000; j += i)
        {
            if (S[j].size() > 8)
            {
                ok = false;
                break;
            }
            for (int l = 0; l < pary[j].size(); ++l)
            {
                if (!jest[pary[j][l].a])
                    rozne.push_back(pary[j][l].a);
                if (!jest[pary[j][l].b])
                    rozne.push_back(pary[j][l].b);
                aktPary.push_back(pary[j][l]);
                jest[pary[j][l].a] = true;
                jest[pary[j][l].b] = true;
            }
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
        {
            for (int j = 0; j < rozne.size(); ++j)
            {
                Z[rozne[j]] = rozne[j];
                jest[rozne[j]] = false;
            }
            continue;
        }
        for (int j = 0; j < aktPary.size(); ++j)
            Union(aktPary[j].a, aktPary[j].b);
        unordered_set<int> r;
        for (int j = 0; j < rozne.size(); ++j)
            r.insert(Find(rozne[j]));
        if (rozne.size() - r.size() <= k)
        {
            cout << i;
            return 0;
        }
        for (int j = 0; j < rozne.size(); ++j)
        {
            Z[rozne[j]] = rozne[j];
            jest[rozne[j]] = false;
        }
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

struct para
{
    int a, b;
};

vector<int> Z;

void Stworz(int n)
{
    for (int i = 0; i < n; ++i)
        Z.push_back(i);
}

int Find(int a)
{
    if (Z[a] == a)
        return a;
    int fa = Find(Z[a]);
    Z[a] = fa;
    return fa;
}

void Union(int a, int b)
{
    int fa = Find(a);
    int fb = Find(b);
    if (fa != fb)
        Z[fa] = fb;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector< vector<para> > pary(1000001);
    vector< set<int> > S(1000001);
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            int r = a[j] - a[i];
            if (S[r].size() <= 8)
            {
                pary[r].push_back({i, j});
                S[r].insert(i);
                S[r].insert(j);
            }
        }
    }
    Stworz(n);
    vector<bool> jest(1000001, false);
    for (int i = 1; i <= 1000000; ++i)
    {
        vector<int> rozne;
        vector<para> aktPary;
        bool ok = true;
        for (int j = i; j <= 1000000; j += i)
        {
            if (S[j].size() > 8)
            {
                ok = false;
                break;
            }
            for (int l = 0; l < pary[j].size(); ++l)
            {
                if (!jest[pary[j][l].a])
                    rozne.push_back(pary[j][l].a);
                if (!jest[pary[j][l].b])
                    rozne.push_back(pary[j][l].b);
                aktPary.push_back(pary[j][l]);
                jest[pary[j][l].a] = true;
                jest[pary[j][l].b] = true;
            }
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
            continue;
        for (int j = 0; j < aktPary.size(); ++j)
            Union(aktPary[j].a, aktPary[j].b);
        set<int> r;
        for (int j = 0; j < rozne.size(); ++j)
            r.insert(Find(rozne[j]));
        if (rozne.size() - r.size() <= k)
        {
            cout << i;
            return 0;
        }
        for (int j = 0; j < rozne.size(); ++j)
        {
            Z[rozne[j]] = rozne[j];
            jest[rozne[j]] = false;
        }
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

struct para
{
    int a, b;
};

vector<int> Z;

void Stworz(int n)
{
    for (int i = 0; i < n; ++i)
        Z.push_back(i);
}

int Find(int a)
{
    if (Z[a] == a)
        return a;
    int fa = Find(Z[a]);
    Z[a] = fa;
    return fa;
}

void Union(int a, int b)
{
    int fa = Find(a);
    int fb = Find(b);
    if (fa != fb)
        Z[fa] = fb;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector< vector<para> > pary(1000001);
    vector< set<int> > S(1000001);
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            int r = a[j] - a[i];
            if (S[r].size() <= 8)
            {
                pary[r].push_back({i, j});
                S[r].insert(i);
                S[r].insert(j);
            }
        }
    }
    Stworz(n);
    vector<bool> jest(1000001, false);
    for (int i = 1; i <= 1000000; ++i)
    {
        vector<int> rozne;
        vector<para> aktPary;
        bool ok = true;
        for (int j = i; j <= 1000000; j += i)
        {
            if (S[j].size() > 8)
            {
                ok = false;
                break;
            }
            for (int l = 0; l < pary[j].size(); ++l)
            {
                if (!jest[pary[j][l].a])
                    rozne.push_back(pary[j][l].a);
                if (!jest[pary[j][l].b])
                    rozne.push_back(pary[j][l].b);
                aktPary.push_back(pary[j][l]);
                jest[pary[j][l].a] = true;
                jest[pary[j][l].b] = true;
            }
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
        {
            for (int j = 0; j < rozne.size(); ++j)
            {
                Z[rozne[j]] = rozne[j];
                jest[rozne[j]] = false;
            }
            continue;
        }
        for (int j = 0; j < aktPary.size(); ++j)
            Union(aktPary[j].a, aktPary[j].b);
        set<int> r;
        for (int j = 0; j < rozne.size(); ++j)
            r.insert(Find(rozne[j]));
        if (rozne.size() - r.size() <= k)
        {
            cout << i;
            return 0;
        }
        for (int j = 0; j < rozne.size(); ++j)
        {
            Z[rozne[j]] = rozne[j];
            jest[rozne[j]] = false;
        }
    }
}


#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

struct para
{
    int a, b;
};

vector<int> Z;

void Stworz(int n)
{
    for (int i = 0; i < n; ++i)
        Z.push_back(i);
}

int Find(int a)
{
    if (Z[a] == a)
        return a;
    int fa = Find(Z[a]);
    Z[a] = fa;
    return fa;
}

int Union(int a, int b)
{
    int fa = Find(a);
    int fb = Find(b);
    if (fa != fb)
    {
        Z[fa] = fb;
        return 1;
    }
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector< vector<para> > pary(1000001);
    for (int i = 0; i < n; ++i)
    {
        for (int j = n - 1; j > i; --j)
        {
            int r = a[j] - a[i];
            if (r < n - k)
                break;
            if (pary[r].size() <= 6)
                pary[r].push_back({i, j});
        }
    }
    Stworz(n);
    vector<bool> jest(1000001, false);
    for (int i = max(1, n - k); i <= 1000000; ++i)
    {
        vector<int> rozne;
        bool ok = true;
        for (int j = i; j <= 1000000; j += i)
        {
            if (pary[j].size() > 6)
            {
                ok = false;
                break;
            }
            for (int l = 0; l < pary[j].size(); ++l)
            {
                if (!jest[pary[j][l].a])
                {
                    rozne.push_back(pary[j][l].a);
                    jest[pary[j][l].a] = true;
                }
                if (!jest[pary[j][l].b])
                {
                    rozne.push_back(pary[j][l].b);
                    jest[pary[j][l].b] = true;
                }
                if (rozne.size() > 8)
                    break;
            }
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
        {
            for (int j = 0; j < rozne.size(); ++j)
            {
                Z[rozne[j]] = rozne[j];
                jest[rozne[j]] = false;
            }
            continue;
        }
        int spojne = rozne.size();
        for (int j = i; j <= 1000000; j += i)
            for (int l = 0; l < pary[j].size(); ++l)
                spojne -= Union(pary[j][l].a, pary[j][l].b);
        if (rozne.size() - spojne <= k)
        {
            cout << i;
            return 0;
        }
        for (int j = 0; j < rozne.size(); ++j)
        {
            Z[rozne[j]] = rozne[j];
            jest[rozne[j]] = false;
        }
    }
}


#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

struct para
{
    int a, b;
};

vector<int> Z;

void Stworz(int n)
{
    for (int i = 0; i < n; ++i)
        Z.push_back(i);
}

int Find(int a)
{
    if (Z[a] == a)
        return a;
    int fa = Find(Z[a]);
    Z[a] = fa;
    return fa;
}

int Union(int a, int b)
{
    int fa = Find(a);
    int fb = Find(b);
    if (fa != fb)
    {
        Z[fa] = fb;
        return 1;
    }
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector< vector<para> > pary(1000001);
    vector< unordered_set<int> > S(1000001);
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            int r = a[j] - a[i];
            if (S[r].size() <= 8)
            {
                pary[r].push_back({i, j});
                S[r].insert(i);
                S[r].insert(j);
            }
        }
    }
    Stworz(n);
    vector<bool> jest(1000001, false);
    for (int i = 1; i <= 1000000; ++i)
    {
        vector<int> rozne;
        bool ok = true;
        for (int j = i; j <= 1000000; j += i)
        {
            if (S[j].size() > 8)
            {
                ok = false;
                break;
            }
            for (int l = 0; l < pary[j].size(); ++l)
            {
                if (!jest[pary[j][l].a])
                {
                    rozne.push_back(pary[j][l].a);
                    jest[pary[j][l].a] = true;
                }
                if (!jest[pary[j][l].b])
                {
                    rozne.push_back(pary[j][l].b);
                    jest[pary[j][l].b] = true;
                }
                if (rozne.size() > 8)
                    break;
            }
            if (rozne.size() > 8)
            {
                ok = false;
                break;
            }
        }
        if (!ok)
        {
            for (int j = 0; j < rozne.size(); ++j)
            {
                Z[rozne[j]] = rozne[j];
                jest[rozne[j]] = false;
            }
            continue;
        }
        int spojne = rozne.size();
        for (int j = i; j <= 1000000; j += i)
            for (int l = 0; l < pary[j].size(); ++l)
                spojne -= Union(pary[j][l].a, pary[j][l].b);
        if (rozne.size() - spojne <= k)
        {
            cout << i;
            return 0;
        }
        for (int j = 0; j < rozne.size(); ++j)
        {
            Z[rozne[j]] = rozne[j];
            jest[rozne[j]] = false;
        }
    }
}