local n = io.read("*n", "*l")
local s = io.read()
local mfl = math.floor
local maxlen = mfl(n / 2)
local found = false
for len = maxlen, 1, -1 do
  local map = {}
  for pos = n - len, 1, -1 do
    map[s:sub(pos + 1, pos + len)] = true
    if map[s:sub(pos + 1 - len, pos)] then
      print(len)
      found = true
      break
    end
  end
  if found then break end
end
if not found then
  print(0)
end
