let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d\n%s" @@ fun n s ->
  let dp = Array.make_matrix (n + 1) (n + 1) 0 in
  let f k =
    for i = 0 to k - 1 do
      for j = 0 to n - k - 1 do
        dp.(i + 1).(j + 1) <-
          if s.[i] = s.[k + j]
          then 1 + dp.(i).(j)
          else max dp.(i + 1).(j) dp.(i).(j + 1)
      done
    done;
    dp.(k).(n - k) in
  Printf.printf "%d\n" @@
  f @@
  upper_bound 0 (n - 1) @@
  fun i -> f i <= f (i + 1)
