def z_algorithm(s)
  n = s.size
  res = Array.new(n, 0)
  res[0] = n
  i, j = 1, 0
  while i < n
    j += 1 while i + j < n && s[j] == s[i + j]
    res[i] = j
    if j == 0
      i += 1
      next
    end
    k = 1
    while i + k < n && k + res[k] < j
      res[i + k] = res[k]
      k += 1
    end
    i += k
    j -= k
  end
  res
end

n = gets.to_i
s = gets.chomp
ans = 0
n.times do |i|
  lcp = z_algorithm(s[i...n])
  lcp.size.times do |j|
    t = lcp[j] > j ? j : lcp[j]
    ans = [ans, t].max
  end
end
p ans
