import Data.List
import Data.Maybe
import Data.Bool
import Control.Monad

main = replicateM 2 (map read.words <$> getLine) >>= print.solve

solve [[n,k], as] = fromJust $ find eval ds where
  eval d = sum (take (n - sum rs `div` d) rs) <= k where
    rs = sort $ map (`mod` d) as
  ds = reverse $ sort $ divisiors $ sum as

divisiors n = concatMap (\x -> bool [] [x, div n x] $ mod n x == 0)
  $ takeWhile ((<=n).(^2)) [1..]
