let N: Int = Int(readLine()!)!
let tmpS = Array(readLine()!.characters)
var S = [Int]()
for i in 0..<N {
    if(tmpS[i] == "a"){
        S[i] = 1
    }
    if(tmpS[i] == "b"){
        S[i] = 2
    }
    if(tmpS[i] == "c"){
        S[i] = 3
    }
    if(tmpS[i] == "d"){
        S[i] = 4
    }
    if(tmpS[i] == "e"){
        S[i] = 5
    }
    if(tmpS[i] == "f"){
        S[i] = 6
    }
    if(tmpS[i] == "g"){
        S[i] = 7
    }
    if(tmpS[i] == "h"){
        S[i] = 8
    }
    if(tmpS[i] == "i"){
        S[i] = 9
    }
    if(tmpS[i] == "j"){
        S[i] = 10
    }
    if(tmpS[i] == "k"){
        S[i] = 11
    }
    if(tmpS[i] == "l"){
        S[i] = 12
    }
    if(tmpS[i] == "m"){
        S[i] = 13
    }
    if(tmpS[i] == "n"){
        S[i] = 14
    }
    if(tmpS[i] == "o"){
        S[i] = 15
    }
    if(tmpS[i] == "p"){
        S[i] = 16
    }
    if(tmpS[i] == "q"){
        S[i] = 17
    }
    if(tmpS[i] == "r"){
        S[i] = 18
    }
    if(tmpS[i] == "s"){
        S[i] = 19
    }
    if(tmpS[i] == "t"){
        S[i] = 20
    }
    if(tmpS[i] == "u"){
        S[i] = 21
    }
    if(tmpS[i] == "v"){
        S[i] = 22
    }
    if(tmpS[i] == "w"){
        S[i] = 23
    }
    if(tmpS[i] == "x"){
        S[i] = 24
    }
    if(tmpS[i] == "y"){
        S[i] = 25
    }
    if(tmpS[i] == "z"){
        S[i] = 26
    }
}

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)
