local n = io.read("*n", "*l")
local s = io.read()
local mfl = math.floor
local maxlen = mfl(n / 2)
local found = false

local function solve(len)
  local map = {}
  local hash = {}
  local tmap = {}
  local thash = {}
  for k = 1, n - len + 1 do
    tmap[k] = s:sub(k, k + len - 1)
    if 5 <= len then
      thash[k] =
        (tmap[k]:sub(1, 1):byte() - 97) +
        (tmap[k]:sub(2, 2):byte() - 97) * 30 +
        (tmap[k]:sub(3, 3):byte() - 97) * 900 +
        (tmap[k]:sub(len - 1, len - 1):byte() - 97) * 27000 +
        (tmap[k]:sub(len, len):byte() - 97) * 810000
    end
  end
  if 5 <= len then
    for pos = n - len, len, -1 do
      map[tmap[pos + 1]] = true
      hash[thash[pos + 1]] = true
      if hash[thash[pos + 1 - len]] and map[tmap[pos + 1 - len]] then
        return true
      end
    end
  else
    for pos = n - len, len, -1 do
      map[tmap[pos + 1]] = true
      if map[tmap[pos + 1 - len]] then
        return true
      end
    end
  end
  return false
end
if not solve(1) then
  print(0)
else
  local lmin, lmax = 1, maxlen + 1
  while 1 < lmax - lmin do
    local len = mfl((lmax + lmin) / 2)
    if solve(len) then
      lmin = len
    else
      lmax = len
    end
  end
  print(lmin)
end
