-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST

main = do
  n <- readLn :: IO Int
  s <- BS.getLine
  let u :: UArray (Int,Int) Int
      u = runSTUArray $ do
        arr <- newArray ((0,0),(n,n)) 0
        forM_ [n-1,n-2..0] $ \i -> do
          let !x = s `BS.index` i
          forM_ [n-1,n-2..i+1] $ \j -> do
            when (x == s `BS.index` j) $ do
              v <- readArray arr (i+1,j+1)
              writeArray arr (i,j) $! min (1 + v) (j - i)
        return arr
  print $ maximum $ elems u
