{-# LANGUAGE BangPatterns #-}

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 <- getLine
  print $ VU.maximum
    $ VU.map (\ !gap -> min gap $ test s $ drop gap s)
    $ VU.tail $ VU.generate n id

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