class String
  def z_algorithm
    len = size

    prefix = Array.new(len, 0)
    j = 0

    (1...len).each do |i|
      if i + prefix[i - j] < j + prefix[j]
        prefix[i] = prefix[i - j]
      else
        k = [0, j + prefix[j] - i].max
        k += 1 while i + k < len && self[k] == self[i + k]
        prefix[i] = k
        j = i
      end
    end

    prefix[0] = len 
    prefix
  end
end

N = gets.to_i
S = gets.chomp
ans = 0

(0...S.size-1).each do |i|
  s = S[i..-1]

  list = s.z_algorithm

  list.each.with_index(1) do |n, i|
    next if n >= i

    ans = n if ans < n
  end
end

puts ans
