open Scanf
open Printf

let readInt () = scanf " %d" (fun x -> x)

let divisors x =
  let l = ref [] in
  let r = ref [] in
  let y = ref 1 in
  while !y * !y <= x do
    if x mod !y = 0 then begin
      l := !y :: !l;
      if x <> !y * !y then r := (x / !y) :: !r
    end;
    incr y
  done;
  List.rev !l @ !r

let cost n a d =
  let open Array in
  let a = map (fun x -> x mod d) a in
  fast_sort compare a;
  let tot = fold_left (+) 0 a in
  assert (tot mod d = 0);
  let m = tot / d in
  let def = ref 0 in
  for i=n-m to n-1 do def := !def + d - a.(i) done;
  !def

let solve n k a =
  let tot = Array.fold_left (+) 0 a in
  let divs = divisors tot in
  List.fold_left (fun cur d -> if cost n a d <= k then d else cur) 1 divs

let main () =
  let n = readInt () in
  let k = readInt () in
  let a = Array.init n (fun _ -> readInt ()) in
  printf "%d\n" (solve n k a)

let () = main ()
