{-# 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 -> test gap s (VU.drop gap s))
    $ VU.tail $ VU.generate n id

test :: Int -> VU.Vector Char -> VU.Vector Char -> Int
test threshold v1 v2
 = VU.foldr (\ (!c1, !c2) cont !prev !maxi ->
              let now_ = prev+1 
              in if | c1 /= c2 -> cont 0 maxi
                    | now_ >= threshold -> threshold
                    | otherwise -> cont now_ (max now_ maxi))
   (\ !prev !maxi -> maxi)
   (VU.zip v1 v2) 0 0
