de = false
require 'prime'
n,k = gets.chomp.split().map(&:to_i)
a = gets.chomp.split().map(&:to_i)
a.sort!
a.reverse!

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(a.inject(:+)).reverse
p divs if de
divs.each do |divisor|
  divided = a.map{|e| e%divisor}.sort.select{|e| e>0}
  p [divisor, 'divided', divided] if de
  rui = []
  divided.each do |e|
    rui.push (rui.last || 0) + e
  end
  rui2 = []
  divided.reverse_each do |e|
    rui2.push (rui2.last || 0) + divisor - e
  end
  rui2.reverse!

  minimum = Float::INFINITY
  size = divided.size
  p ['rui', rui] if de
  p ['rui2', rui2] if de
  (size-1).times do |i|
    diff = [rui[i], rui2[i+1]].max
    minimum = diff if minimum > diff
  end

  p ['minim', minimum] if de
  if minimum <= k
    puts divisor
    break
  end
end
