let () =
    let split s = let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let test a target k =
        let r = List.map (fun v -> v mod target) a in
        let r = Array.of_list (List.sort compare r) in
        let s = Array.fold_left (+) 0 r  / target in
        let l = Array.length r in
        let rec loop q acc =
            if q + s = l then acc else loop (q + 1) (acc + r.(q))
        in
        loop 0 0 <= k
    in
    let main () =
        let n, k = Scanf.sscanf (read_line ()) "%d %d" (fun n k -> n, k) in
        let a = split (read_line ()) in
        let s = List.fold_left (+) 0 a in
        let rec loop i acc =
            if i * i > s then acc else
            let acc = if s mod i <> 0 then acc else max acc (
                max (if test a i k then i else acc)
                    (if test a (s / i) k then (s / i) else acc)
            )
            in
            loop (i + 1) acc
        in
        Printf.printf "%d\n" (loop 1 (-1))
    in
    main ()