N=gets.to_i
S=gets.chomp.codepoints
dp=Array.new(N,0)
next_dp=Array.new(N,0)
ans=0
(1..N-1).to_a.reverse.each do |j|
    cnt=0
    if j==N-1
        (0..j-1).to_a.reverse.each do |i|
            if S[i]==S[j]
                next_dp[i]+=1
                cnt=1
            end
        end
    else
        (0..j-1).to_a.reverse.each do |i|
            if S[i]==S[j]
                e=dp[i+1]+1
                next_dp[i]=(e < j-i) ? e : j-i
                cnt=cnt<next_dp[i] ? next_dp[i] : cnt
            end
        end
    end
    dp=next_dp.clone
    next_dp=Array.new(N,0)
    ans = ans < cnt ? cnt : ans
end
p ans