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