import Data.List

solve x _ [] = x
solve x (a:s) (b:t) = max x $ solve y s t where
  y = if a == b then x + 1 else 0

main = do
  n <- readLn
  s <- getLine
  print $ maximum $
    [min (n - length t) (solve 0 s t) | t <- tails s]
