local floor = math.floor
-- binary search
-- https://golang.org/src/sort/search.go?s=2246:2286#L49
local function find_min_true(n, f)
    local function loop(i, j)
        if i == j then
            return i
        end
        local h = floor((i + j) / 2)
        if f(h) then
            return loop(i, h)
        else
            return loop(h + 1, j)
        end
    end
    return loop(1, n + 1)
end


local N = io.read("*n", "*l")
local S = io.read("*l")
local sub = string.sub
local find = string.find
local function search()
    -- false if len is OK
    local function judge(len)
        for l1=1,N+1-2*len do
            local subst = sub(S, l1, l1+len-1)
            local result = find(S, subst, l1+len, true)
            --print("len", len, "l1", l1, "subst", subst, "result", result)
            if result then
                return false
            end
        end
        return true -- len is NG
    end
    return find_min_true(2500, judge)
end
local ans = search()
if ans == 0 then
    print(0)
else
    print(ans-1)
end