open Scanf
open Printf

let rec scan_list = function
  | 1 -> scanf "%d" (fun k -> [k])
  | n -> scanf "%d " (fun k -> k :: scan_list (n-1))

let rec gcd a b = if b = 0
  then a
  else gcd b (a mod b)

let lcm a b = a * (b / (gcd a b))

let rec seq = function
  | 0 -> []
  | n -> n :: seq (n-1)

let f a m = List.fold_left ( + ) 0 (List.map (fun x -> m mod x) a)

let () = let lst = scanf "%d\n" scan_list in
  printf "%d\n" (List.fold_left max 0 (List.map (f lst) (seq @@ List.fold_left lcm 1 lst)))