N = gets.chomp.to_i
S = gets.chomp
a = Array.new(N){Array.new(N,0)}
answer = 0
for i in 0...N-1 do
    for j in i+1...N do
        if S[i] == S[j]
            a[i][j] += 1
        end
    end
end

i = N-1
while i > 0
    now = 0
    max = 0
    for j in 0...N-i do
        if a[j][j+i] == 1
            now += 1
        else
            now = now > i ? i : now
            max = now > max ? now : max
            now = 0
        end
    end
    now = now > i ? i : now
    max = now > max ? now : max
    answer = max > answer ? max : answer
    i -= 1
end

puts answer