import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val S = readInputLine()
    
    var ans = 0
    
    for (i in 0 until N) {
        val tmp = zAlgorithm(S.substring(i..N - 1))
        ans = tmp.foldIndexed(ans) { index, acc, len -> 
            if (index == 0 || len == 0) acc
            else Math.max(acc, Math.min(len, index))
        }
        
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}

fun zAlgorithm(s: String): IntArray {
    val ret = IntArray(s.length)
    
    ret[0] = s.length
    
    var i = 1
    var j = 0
    
    while (i < s.length) {
        while (i + j < s.length && s[j] == s[i + j]) {
            j++
        }
        ret[i] = j
        if (j == 0) {
            i++
            continue
        }
        var k = 1
        while (i + k < s.length && k + ret[k] < j) {
            ret[i + k] = ret[k]
            k++
        }
        i += k
        j -= k
    }
    
    return ret
}
