n = gets.to_i
s = gets.chomp

i = j = a = 0
while j < n - 1
    #p [i, j, j + j - i + 1, s[j+1..-1][s[i..j]]]
    if j + j - i + 1 >= n
        i == j ? i = j += 1 : i += 1
    elsif s[j+1..-1][s[i..j]]
        a = [a, j - i + 1].max
        j += 1
    else
        i == j ? i = j += 1 : i += 1
    end
end
p a