import collection.mutable.PriorityQueue

object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val s = sc.next
    for(len <- (s.length-1)/2 to (1, -1)) {
      for(i <- 0 to s.length-len) {
        for(j <- i+len to s.length-len) {
          // println(s.substring(i, i+len))
          // println(s.substring(j, j+len))
          if (s.substring(i, i+len) == s.substring(j, j+len)) {
            println(len)
            System.exit(0)
          }
        }
      }
    }
    println(0)
  }
}
