let N: Int = Int(readLine()!)!
let tmpS = Array(readLine()!.characters)
let S = Array[Int]()
for i in 0..<N {
    S[i] = Int(tmpS[i])
}

var ng:Int = N
var ok:Int = 0
let mod = 1000000007
let x = 998244353
while(ng - ok > 1){
    var l:Bool = false
    var hashTable = [Int]()
    var mid:Int = (ok + ng) / 2
    
    var hash:Int = 0
    for i in 0..<mid {
        hash = (hash * x + Int(S[i])) % mod
    }
    
    var used:Set = [hash]
    var pow:Int = 1
    for _ in 0..<mid {
        pow *= x;
        pow %= mod
    }
    for i in mid..<N {
        hash = ((hash * x + S[i] - S[i - mid] * pow) % mod + mod) % mod
        if(used.contains(hash)){
            l = true
        }
        used.insert(hash)
    }
    
    if(l){
        ok = mid
    }else{
        ng = mid
    }
    
}
print(ok)
