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
    var rw = new Array[Int](0) :+ 0
    var sum = 0
    val a = 'a'.toInt
    s.foreach { v =>
      sum += (v.toInt - a)
      rw = rw :+ sum
    }
    //println(rw.deep)
    for(len <- (s.length)/2 to (1, -1)) {
      for(i <- 0 to s.length-len) {
        for(j <- i+len to s.length-len) {
          if (rw(i+len)-rw(i) == rw(j+len)-rw(j)) {
            //println(s.substring(i, i+len))
            //println(s.substring(j, j+len))
            if ((0 to len).forall {x => s(i+x) == s(i+x)}) {
              println(len)
              System.exit(0)
            }
          }
        }
      }
    }
    println(0)
  }
}
