let () =
    let main () =
        let n = int_of_string (read_line ()) in
        let s = read_line () in
        let rec loop_i i acc =
            let rec loop_j j acc =
                let rec loop_k k =
                    if j + k = n then k else
                        if i + k = j then k else
                        if s.[i + k] <> s.[j + k] then k else
                            loop_k (k + 1)
                in
                if j = n then acc else loop_j (j + 1) (max acc (loop_k 0))
            in
            if i = n - 1 then acc else loop_i (i + 1) (loop_j (i + 1) acc)
        in
        let r = loop_i 0 0 in
        Printf.printf "%d\n" r
    in
    main ()