g a [] = 0
g a s@(t:xs) = let la = length a
                   p = take la s
               in if a == p then la
                            else g a xs

sq [] = return []
sq (x:xs) = [x] : [x:p | p <- sq xs]

counts [] = []
counts a@(x:xs) = map (\t -> g t $ drop (length t) a ) (sq a) ++ counts xs

main = do
  n <- getLine
  x <- getLine
  print $ maximum $ counts x