def Z_Algorithm_ex(s, lim)
  ret = Array.new(s.size, 0)
  wk = 0
  i, j = [1, 0]
  i = lim if lim > 0
  while i < s.size do
    break if s.size - i < lim
    while i+j < s.size && s[j] == s[i+j] do j += 1 end
    ret[i] = j
    wk = calc(wk, i, j)
    (i += 1; next) if j == 0
    k = 1
    while i+k < s.size && k + ret[k] < j do
      ret[j+k] = ret[k]
      wk = calc(wk, j+k, ret[k])
      k += 1
    end
    i += k
    j -= k
  end
  wk
end

def calc(wk, i, j)
  tmp = i > j ? j : i
  wk < tmp ? tmp : wk
end

N = gets.to_i
S = gets.chomp.chars

ans = 0
(0..(N-2)).each{|i|
  break if i + ans > N
  wk = Z_Algorithm_ex(S[i...N], ans)
  ans = wk if ans < wk
}

puts ans
