{-# OPTIONS_GHC -O2 #-} import qualified Control.Arrow as Arrow import qualified Data.List as List import qualified Data.ByteString.Char8 as BSC8 import qualified Data.Maybe as Maybe readInts :: IO [Int] readInts = map (fst . Maybe.fromJust . BSC8.readInt) . BSC8.words <$> BSC8.getLine main :: IO () main = do n <- readLn :: IO Int xs <- readInts if n < 3 || n > 7 then print (-1) else print $ solve xs solve :: [Int] -> Int solve xs = if l > 1 || l == 0 then -1 else g $ filter snd ys where tables = map major [0..11] ys = map (head Arrow.&&& ok xs) tables l = length $ filter snd ys g [(a, b)] = a ok :: [Int] -> [Int] -> Bool ok [] _ = True ok (x:xs) ys = (List.elem x ys) && (ok xs ys) major :: Int -> [Int] major n = [(n + x) `mod` 12 | x <- [0, 2, 4, 5, 7, 9, 11]]