program max_gcd
  implicit none
  integer :: n, k, a(500) = 0, m, d(100000) = 0, num = 0, i, j
  integer :: x(500) = 0, y, z
  read(*,*) n, k
  read(*,*) a(1:n)
  m = sum(a(1:n))
  do i = 1, m
    if (i*i > m) exit
    if (mod(m,i) /= 0) cycle
    num = num+1
    d(num) = i
    if (m/i /= i) then
      num = num+1
      d(num) = m/i
    end if
  end do
  call quick_sort(d(1:num))
  call quick_sort(a(1:n))
  do i = num, 1, -1
    if (n > m/d(i)) then
      z = 0
      do j = n-m/d(i)+1, n
        z = z+abs(d(i)-a(j))
      end do
      if (k >= m-z) then
        write(*,'(i0)') d(i)
        stop
      end if
      cycle
    end if
    x = mod(a(1:n),d(i))
    y = 0
    z = 0
    do j = 1, n
      if (x(j) < d(i)-x(j)) then
        y = y+x(j)
      else if (x(j) > d(i)-x(j)) then
        z = z+d(i)-x(j)
      else
        if (y < z) then
          y = y+x(j)
        else
          z = z+d(i)-x(j)
        end if
      end if
    end do
    if (max(y,z) <= 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
    n = size(a)
    l = 1
    r = n
    p = a((l+r)/2)+a(l)+a(r)-max(a((l+r)/2),a(l),a(r))-min(a((l+r)/2),a(l),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