program max_gcd
  implicit none
  integer :: n, a(500) = 0, s, d(100000) = 0, num = 0, i, j, x(500) = 0
  integer(8) :: k, m, p, q
  read(*,*) n, k
  read(*,*) a(1:n)
  s = sum(a(1:n))
  do i = 1, s
    if (i*i > s) exit
    if (mod(s,i) /= 0) cycle
    num = num+1
    d(num) = i
    if (s/i /= i) then
      num = num+1
      d(num) = s/i
    end if
  end do
  call quick_sort(d(1:num))
  do i = num, 1, -1
    x(1:n) = mod(a(1:n),d(i))
    call quick_sort(x(1:n))
    m = 1e18
    q = sum(int(d(i)-x(1:n),8))
    p = 0_8
    do j = 1, n
      p = p+int(x(j),8)
      q = q-int(d(i)-x(j),8)
      m = min(m,max(p,q))
    end do
    if (m <= k) then
      write(*,'(i0)') d(i)
      stop
    end if
  end do
  stop
contains
  recursive subroutine quick_sort(a)
    implicit none
    integer, intent(inout) :: a(:)
    integer :: p, c
    integer :: n, l, r, m
    n = size(a)
    l = 1
    r = n
    m = (l+r)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      c = a(l)
      a(l) = a(r)
      a(r) = c
      l = l+1
      r = r-1
    end do
    if (l > 2) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end subroutine quick_sort
end program max_gcd