import Data.List
f [] a b = 13
f (xs@(x:_):xss) a b 
  | n >= 3 = 0
  | n == 2 = (x-a) `min` (y-b) `min` ((x`div`6*6-x`mod`6)*2) `min` f xss x y
  | x-a < y-b = (y-b) `min` f xss a y
  | otherwise = (x-a) `min` f xss x b
  where 
    n = length xs
    y = (24 - x) `mod` 24
main = do
  getLine
  ds <- map read . words <$> getLine
  print $ f (group $ sort ds) 0 0