n=gets.to_i
s=gets.chomp

def z(s)
  a=Array.new(s.size)
  a[0]=s.size
  i,j=1,0
  while i<s.size
    j+=1 while i+j<s.size and s[j]==s[i+j]
    a[i]=j
    if j==0
      i+=1
      next
    end
    k=1
    (a[i+k]=a[k]; k+=1) while i+k < s.size() and k+a[k] < j
    i += k
    j -= k
  end
  return a
end

puts (0..(n-2)).map{|i| z(s[i,n-i]).map.with_index{|x,j| (j<x)? j:x}.max }.max