n = gets.strip.to_i
ss=gets.strip

def z_alg(s)
  res = Array.new(s.length, 0)
  i=1
  j=0

  while(i<s.length)
    # p s
    # p [s[j], s[i+j], res]
    # byebug
    while(i+j<s.length && s[j]==s[i+j]) do
      j+=1
    end

    res[i]=j

    if j.zero?
      i+=1
      next
    end

    k=1
    while(i+k < s.length && k+res[k]<j)do
      res[i+k]=res[k]
      k+=1
    end
    i+=k
    j-=k
  end

  res
end

result = 0

ss.length.times do |i|
  len = i+1
  current = ss[i..ss.length-1]
  c = z_alg(current)

  c.length.times do |j|
    l = [j, c[j]].min
    result = [result, l].max
  end

  # p z_alg(current)
end

p result
