#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

#define REP(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v),0)

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"\t";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int gcd(vector<int> &v) {
    sort(ALL(v));
    bool flag=true;
    rep(i, v.size()) {
        if(i>0&&v[i]%v[0]!=0) {
            flag=false;
        }
    }

    if(flag) {
        return v[0];
    } else {
        rep(i, v.size()) {
            if(i>0&&v[i]>v[0]) {
                v[i]=v[i]-v[0];
            }
        }
        gcd(v);
    }
}

vector<int> divisor(int n) {
    vector<int> ret;
    for(int i=1; i*i<=n; i++) {
        if(n%i==0) {
            ret.pb(i);
            if(i*i!=n) {
                ret.pb(n/i);
            }
        }
    }
    sort(ALL(ret));
    return ret;
}

int sumAbs(vector<int> v) {
    int res=0;
    rep(i, v.size()) {
        if(v[i]>0) {
            res+=v[i];
        }
    }
    return res;
}

int cost(vector<int> v,int gcd) {
    dbg(v);
    int sum=sum(v);
    //降順ソート
    sort(ALL(v), greater<>());
    if(sum==0) {
        return sumAbs(v);
    } else if(sum>0) {
        int minCost=INF;
        //sumの約数(adjust[i])をi+1個先頭から引いて最後に付け加える)
        vector<int> cpV=v;
        if(sum/gcd<=cpV.size()) {
            rep(j, sum/gcd) {
                int pop=cpV.front();
                cpV.erase(cpV.begin());
                cpV.pb(pop-gcd);
            }
            sort(ALL(cpV), greater<>());
            dbg(cpV);
            if(sum(cpV)==0) {
                minCost=min(minCost, sumAbs(cpV));
            }
        }
        return minCost;
    } else {
        sum=-1*sum;
        int minCost=INF;
        vector<int> cpV=v;
        if(sum/gcd<=cpV.size()) {
            rep(j, sum/gcd) {
                int pop=cpV.back();
                cpV.pop_back();
                cpV.insert(cpV.begin(), pop+gcd);
            }
            sort(ALL(cpV), greater<>());
            dbg(cpV);
            if(sum(cpV)==0) {
                minCost=min(minCost, sumAbs(cpV));
            }
        }
        return minCost;
    }
}

int solve() {
    int n;
    int k;
    cin>>n>>k;
    vector<int> v(n);
    int sum=0;
    rep(i, n) {
        cin>>v[i];
        sum+=v[i];
    }
    int minCost=INF;
    vector<int> divisors=divisor(sum);
    sort(ALL(divisors), greater<>());
    rep(i, divisors.size()) {
        int gcd=divisors[i];
        int diff;
        int diffSum=0;
        vector<int> diffV(n);
        rep(j, n) {
            diff=v[j]%gcd;
            if(diff>gcd/2) {
                diff=diff-gcd;
            }
            diffV[j]=diff;
            diffSum+=diff;
        }
        dbg(gcd);
        dbg(diffV);
        dbg(diffSum);
        int c=cost(diffV,gcd);
        dbg(c);
        if(c<=k){
            return  gcd;
        }
    }
    return INF;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans = solve();
    cout << ans << endl;
    return  0;
}


Measured memory_bytes: 384