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 t =
                if j + i = n then max acc (min t i) else
                    loop_j (j + 1) acc (if s.[j] = s.[j + i] then t + 1 else 0)
            in
            if i > n - acc then acc else loop_i (i + 1) (loop_j 0 acc 0)
        in
        Printf.printf "%d\n" (loop_i 0 0)
    in
    main ()