[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let ss = (read string).ToCharArray()

    let dp = Array2D.create (n + 1) (n + 1) 0

    for i = n - 1 downto 0 do
        for j = n - 1 downto 0 do
            if ss.[i] = ss.[j] then
                dp.[i,j] <- dp.[i+1,j+1] + 1

    let mutable ans = 0
    for i = 0 to n - 1 do
        for j = 0 to n - 1 do
            if i < j then
                ans <- max ans (min dp.[i,j] (j - i))

    printfn "%i" ans
    0