n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
sum=a.inject(0){|sum,i| sum+=i}
require 'prime'
primes=sum.prime_division
res=0
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
divs = divisors(sum).reverse

divs.each do |i|
  num_action=a.inject(0){|sum,j| sum+=(i-j).abs}
  if num_action < k
    puts i
    exit
  end
end
