require 'set'
N = gets.to_i
S = gets.chomp.chars

NG_MEMO = {}
OK_MEMO = {}
def ok(s, span)
  (0..(N - 1 - span)).each do |i|
    ((i + span)..(N - 1)).each do |j|
      ng_span = NG_MEMO[[i, j]]
      next if ng_span && ng_span <= span
      ok_span = OK_MEMO[[i, j]]
      return true if ok_span && ok_span >= span
      c = 0
      ret = true
      while c < span
        unless s[i + c] == s[j + c]
          ret = false
          NG_MEMO[[i, j]] = span
          break
        end
        c += 1
      end
      if ret
        OK_MEMO[[i, j]] = span
        return true
      end
    end
  end
  false
end

ans = (1..(N - 1)).bsearch do |span|
  !ok(S, span)
end
if ans.nil?
  puts '0'
else
  puts(ans - 1)
end
