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

solve :: U.Vector Char -> Int -> Int
solve !s !d = min d $ U.maximum $ U.scanr' (\(c1,c2) !x -> if c1 == c2 then x + 1 else 0) 0 $ U.zip s (U.drop d s)

main = do
  n <- readLn :: IO Int
  s <- BS.getLine
  let s' = U.generate (BS.length s) $ BS.index s
  print $ maximum [solve s' d | d <- [1..n]]
