N=gets.to_i
S=gets.chomp
(2..N/2).to_a.reverse.each do |i|
    (N-i+1).times do |j|
        check=Regexp.new(S[j,i])
        if j!=0 && check =~ S[0..j] || j+i+1!=N && check =~ S[j+i+1,-1]
            puts i
            exit
        end
    end
end
puts 0
