import scala.collection.mutable
import scala.io.StdIn
import java.util._
import util.control.Breaks._

object Main extends App {
  StdIn.readLine()
  val l = StdIn.readLine()
  var max = 0
  for (c <- 0 until l.size){
    for(i <- 1 until l.size-c){
      if (l(c+i) == l(c)){
        breakable {
         // println(c,i)
          if (Math.min(i, l.size-c-i) > max) {
            for (j <- 0 until Math.min(i, l.size - c - i)) {
              //println(l(c + i + j), l(c + j))
              if (l(c + i + j) == l(c + j)) {
                if (j + 1 > max) max = j + 1
              } else break
            }
          }
        }
      }
    }
  }
  println(max)
}
