import Data.Vector.Unboxed (Vector, (!))
import qualified Data.Vector.Unboxed as U

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

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