let () = Scanf.scanf "%d\n" @@ fun n -> let t = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in let check d x = if List.mem ((x-d+12) mod 12) [0;2;4;5;7;9;11] then true else false in let num = ref [] in for i = 0 to 12 do let b = Array.fold_left (fun b x -> b && (check i x)) true t in if b then num := i :: !num done; Printf.printf "%d\n" (if List.length !num = 1 then List.hd !num else -1)