class Array
  def z_algorithm
    n = size
    c = 0
    z = [0] * n
    ( 1 ... n ).each do |i|
      l = i - c
      if l < z[c] - z[l]
        z[i] = z[l]
      else
        j = [0, z[c] - l].max
        j += 1 while i + j < n && self[j] == self[i+j]
        z[i] = j
        c = i
      end
    end
    # z[0] = n
    z
  end
end

n = gets.to_s.to_i
s = gets.to_s.chomp.bytes

ans = 0
(n-1).times do |i|
  lcp = s[i, n-i].z_algorithm
  lcp.size.times do |j|
    l = [lcp[j], j].min
    ans = l if ans < l
  end
end

puts ans