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 let i = ref 0 in while !i < n do let d = t.(!i) in let b = Array.fold_left (fun b x -> b && (check d x)) true t in if b then num := d :: !num; i := !i + 1 done; Printf.printf "%d\n" (if List.length !num = 1 then List.hd !num else -1)