l = gets.to_i
s = gets.chomp!
max = 0

until s == "" do
    a = [l]
    l -= 1
    i = 1
    j = 0

    while i <= l do
        while i + j <= l && s[j] == s[i+j] do
            j += 1
        end

        a << j
        max = j if j <= i && max < j

        if j == 0 
            i += 1
        else
            k = 1
            while i + k <= l && k + a[k] < j do
                a[i+k] = a[k]
                k += 1
            end
            i += k
            j -= k
        end
    end

    a.clear
    s.slice!(0)
end

puts max