N = gets.to_i
S = gets.chomp

def zm(s)
  z = Array.new(l = s.length, 0)
  j = 0
  (1 ... l).each do |i|
    if i + z[i - j] < j + z[j]
      z[i] = z[i - j]
    else
      k = [0, j + z[j] - i].max
      k += 1 while i + k < l && s[k] == s[i + k]
      z[i] = k
      j = i
    end
  end
  z.map.with_index{|n, i| [n, i].min}.max
end

puts (0 ... N).map{|i| zm(S[i .. -1])}.max