{-# LANGUAGE BangPatterns, MultiWayIf #-}

import Prelude
import Data.Bits
import Data.List
import Data.Maybe
import Data.Tuple
import Data.Ord
import Data.Int
import Data.Word
import Data.Char
import Data.Ratio
import Data.Function
import Data.STRef
import Data.IORef
import Data.Monoid
import Data.Functor
import Data.Data
import Data.Typeable
import GHC.Generics
import System.IO
import Control.Arrow
import Control.Applicative ((<$>))
import qualified Data.Vector.Unboxed as VU


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
