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