from collections import deque

N = int(input())
S = input()

def exists(length):
    que = deque()
    V = set()
    for left in range(N - length + 1):
        if left > length - 1:
            V.add(que.popleft())
        T = S[left: left + length]
        if T in V:
            return True
        que.append(T)
    return False

ok = 0
ng = N
while ng - ok > 1:
    mid = (ok + ng) // 2

    if exists(mid):
        ok = mid
    else:
        ng = mid

print(ok)
 from collections import deque N = int(input()) N int(input()) int input() input S = input() S input() input def exists(length):
    que = deque()
    V = set()
    for left in range(N - length + 1):
        if left > length - 1:
            V.add(que.popleft())
        T = S[left: left + length]
        if T in V:
            return True
        que.append(T)
    return False exists que = deque() que deque() deque V = set() V set() set for left in range(N - length + 1):
        if left > length - 1:
            V.add(que.popleft())
        T = S[left: left + length]
        if T in V:
            return True
        que.append(T)
     left range(N - length + 1) range N - length + 1 N - length N length 1 if left > length - 1:
            V.add(que.popleft())
         left > length - 1 left length - 1 length 1 V.add(que.popleft()) V.add V add que.popleft() que.popleft que popleft T = S[left: left + length] T S[left: left + length] S left: left + length left left + length left length if T in V:
            return True
         T in V T V return True True que.append(T) que.append que append T return False False length length ok = 0 ok 0 ng = N ng N while ng - ok > 1:
    mid = (ok + ng) // 2

    if exists(mid):
        ok = mid
    else:
        ng = mid ng - ok > 1 ng - ok ng ok 1 mid = (ok + ng) // 2 mid (ok + ng) // 2 ok + ng ok ng 2 if exists(mid):
        ok = mid
    else:
        ng = mid exists(mid) exists mid ok = mid ok mid ng = mid ng mid print(ok) print ok S = input() input() S ng = N N ng mid = (ok + ng) // 2 (ok + ng) // 2 mid def exists(length):
    que = deque()
    V = set()
    for left in range(N - length + 1):
        if left > length - 1:
            V.add(que.popleft())
        T = S[left: left + length]
        if T in V:
            return True
        que.append(T)
    return False def exists(length):
    que = deque()
    V = set()
    for left in range(N - length + 1):
        if left > length - 1:
            V.add(que.popleft())
        T = S[left: left + length]
        if T in V:
            return True
        que.append(T)
    return False exists ok = 0 0 ok ng = mid mid ng N = int(input()) int(input()) N ok = mid mid ok
from collections import deque

N = int(input())
S = input()

def exists(length):
    que = deque()
    V = set()
    for left in range(N - length + 1):
        if left > length - 1:
            V.add(que.popleft())
        T = S[left: left + length]
        if T in V:
            return True
        que.append(T)
    return False

ok = 0
ng = N
while ng - ok > 1:
    mid = (ok + ng) // 2

    if exists(mid):
        ok = mid
    else:
        ng = mid

print(ok)

