N = gets.chomp.to_i
S = gets.chomp
answer = 0

i = N-1
while i > 0
    now = 0
    max = 0
    for j in 0...N-i do
        if S[j] == S[j+i]
            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