fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val S = readLine()!!

    var res = 0
    for (k in 1 until N) {
        var p = 0
        for (i in 0 until (N - k)) {
            if (S[i] != S[k + i]) {
                p = i + 1
            } else {
                if (i >= k + p) {
                    p++
                }
                res = Math.max(res, i - p + 1)
            }
        }
    }

    println(res)
}
