import java.io.{BufferedReader, InputStreamReader}

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))

    val n = in.readLine.toInt
    val str = in.readLine
    val memo = Array.ofDim[Int](n, n)
    var max = 0

    (0 until n).foreach { col =>
      val currentCh = str.charAt(col)
      (col + 1 until n).foreach { row =>
        val iterCh = str.charAt(row)
        if (currentCh == iterCh) {
          val point =
            if (col == 0) {
              1
            } else {
              memo(row - 1)(col - 1) + 1
            }
          if (col < row - point + 1) {
            max = Math.max(max, point)
          }
          memo(row)(col) = point
        }
      }
    }
    System.out.println(max)
  }
}