//object ABC141EJvm {
object Main {

  def main(args: Array[String]): Unit = println(solve(parse()))

  def solve(input: (Int, String)): Int = {
    val (n, s) = input
    val maxSubStringLength = s.length / 2 - (if (s.length % 2 == 0) 1 else 0)
    val r = (1 to maxSubStringLength).reverse.find { i =>
      (0 until i).exists { j =>
        val slicedString = s.slice(j, j + i)
        (s.take(j) ++ s.drop(j + i)).contains(slicedString)
      }
    }.toList
    if (r.isEmpty) 0 else r.max
  }

  def parse(): (Int, String) = {
    val input: List[String] = io.Source.stdin.getLines().toList
    val n :: s :: Nil = input
    (n.toInt, s)
  }
}
