{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import Data.Char


main :: IO ()
main = do
  n <- readLn :: IO Int
  s <- getLine :: IO String
  print $ solve n s

solve n s = maximum [ uncurry commonSubsequence $ splitAt i s | i <- [1..(n-1)]]
  where
    commonSubsequence :: String -> String -> Int
    commonSubsequence xs ys = last $ foldl' scanY headRow xs
      where
        m = length ys
        headRow = replicate (m + 1) 0 :: [Int]
        scanY :: [Int] -> Char -> [Int]
        scanY prevRow !x = scanl' f 0 yvprev
          where
            yvprev = zip3 ys prevRow $ tail prevRow
            f :: Int -> (Char, Int, Int) -> Int
            f !v (!y, !a, !b) = if x == y 
                            then 1 + a
                            else max b v
