solve :: String -> Int -> Int
solve s d = min d $ maximum $ scanl f 0 $ sd where
  sd = zip s $ drop d s
  f x (a, b)
    | a == b = x + 1
    | otherwise = 0

main = do
  n <- readLn
  s <- getLine
  print $ maximum $ [solve s d | d <- [0..n-1]]
