n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
sum=a.inject(0){|s,i| s+=i}
require 'prime'
def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end

def combi(res, ary)
  a=ary.shift
  if not ary.empty?
    combi(res.product(a), ary)
  else
    res.product(a)
  end
end

divs = divisors(sum).reverse
#puts divs

divs.each do |i|
  num_action=a.inject(0){|sum,j| sum+=[j%i, i-j%i, j].min}
  if num_action <= k*2
    puts i
    exit
  end
end
