import Data.List
f [] a b = (b-a)
f (x:xs) a b
  | x-a < b-y = (b-y) `min` f xs a y
  | otherwise = (x-a) `min` f xs x b 
  where y = 24-x
main = do
  getLine
  ds <- map read . words <$> getLine
  print $ f (sort ds) 0 24