len = gets.to_i
str = gets.chomp
max_all = 0
len.times do |t|
  s = str[t..-1]
  z = Array.new{len}
  z[0] = len
  i = 1
  j = 0
  max_match = 0
  while i < len
    while i+j < len && s[j] == s[i+j]
      j += 1
    end
    z[i] = j
    max_match = z[i] if max_match < z[i] && i >= z[i]
    if j == 0
      i += 1
      next
    end
    k = 1
    while k < j && k+z[k] < j
      z[i+k] = z[k]
      max_match = z[i+k] if max_match < z[i+k] && i+k>= z[i+k]
      k += 1
    end
    i += k
    j -= k
  end
  max_all = max_match if max_all < max_match
end
puts max_all