{-# LANGUAGE BangPatterns, MultiWayIf #-}

import Control.Applicative ((<$>))
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as BS


main :: IO ()
main = do
  n <- read <$> getLine
  s <- VU.unfoldrN n BS.uncons <$> BS.getLine
  print $ VU.maximum
    $ VU.map (\ !gap -> max gap $ test s $ VU.drop gap s)
    $ VU.tail $ VU.generate n id

test :: VU.Vector Char -> VU.Vector Char -> Int
test v1 v2
 = VU.maximum
   $ VU.scanl' (\ !l !b -> if b then l+1 else 0) (0::Int)
   $ VU.zipWith (==) v1 v2
