def divisors(n)
  r = []
  1.upto(n) do |i|
    break unless i <= n / i
    next unless (n % i).zero?
    r << i
    r << n / i if i != n / i
  end
  r
end

def worm(a, d)
  l, r = 0, N - 1
  s = a1 = a2 = 0
  while l <= r
    if s <= 0
      s += a[l]
      a1 += a[l]
      l += 1
    else
      s -= d - a[r]
      a2 += d - a[r]
      r -= 1
    end
  end
  [a1, a2].min
end

N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
S = A.inject(:+)

p divisors(S).map{|d| worm(A.map{|i| i % d}.sort, d) <= K ? d : 1}.max
