local n = io.read("*n", "*l")
local s = io.read()
local bt = {}
local mma, mmi = math.max, math.min
for i = 1, n do
  bt[i] = s:sub(i, i):byte() - 97
end
local ret = 0
for i = 1, n do
  local cnt = 0
  for j = 1, n - i do
    if bt[j] == bt[j + i] then
      cnt = cnt + 1
    else
      cnt = 0
    end
    ret = mma(ret, mmi(i, cnt))
  end
end
print(ret)
