n=int(input())
s=input()

from collections import defaultdict

def check(l):
    d = defaultdict(lambda: -1)
    for i in range(n-l+1):
        if d[s[i:i+l]] != -1:
            if d[s[i:i+l]] + l <= i:
                return True
        else:
            d[s[i:i+l]]=i
    return False

ok=0
ng=len(s)

while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if check(mid):
        ok=mid
    else:
        ng=mid

print(ok) n=int(input()) n int(input()) int input() input s=input() s input() input from collections import defaultdict def check(l):
    d = defaultdict(lambda: -1)
    for i in range(n-l+1):
        if d[s[i:i+l]] != -1:
            if d[s[i:i+l]] + l <= i:
                return True
        else:
            d[s[i:i+l]]=i
    return False check d = defaultdict(lambda: -1) d defaultdict(lambda: -1) defaultdict lambda: -1 -1 for i in range(n-l+1):
        if d[s[i:i+l]] != -1:
            if d[s[i:i+l]] + l <= i:
                return True
        else:
            d[s[i:i+l]]=i
     i range(n-l+1) range n-l+1 n-l n l 1 if d[s[i:i+l]] != -1:
            if d[s[i:i+l]] + l <= i:
                return True
        else:
            d[s[i:i+l]]=i
     d[s[i:i+l]] != -1 d[s[i:i+l]] d s[i:i+l] s i:i+l i i+l i l -1 if d[s[i:i+l]] + l <= i:
                return True
         d[s[i:i+l]] + l <= i d[s[i:i+l]] + l d[s[i:i+l]] d s[i:i+l] s i:i+l i i+l i l l i return True True d[s[i:i+l]]=i d[s[i:i+l]] d s[i:i+l] s i:i+l i i+l i l i return False False l l ok=0 ok 0 ng=len(s) ng len(s) len s while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if check(mid):
        ok=mid
    else:
        ng=mid abs(ok-ng)>1 abs(ok-ng) abs ok-ng ok ng 1 mid=(ok+ng)//2 mid (ok+ng)//2 ok+ng ok ng 2 if check(mid):
        ok=mid
    else:
        ng=mid check(mid) check mid ok=mid ok mid ng=mid ng mid print(ok) print ok ng=mid mid ng ok=0 0 ok n=int(input()) int(input()) n ok=mid mid ok def check(l):
    d = defaultdict(lambda: -1)
    for i in range(n-l+1):
        if d[s[i:i+l]] != -1:
            if d[s[i:i+l]] + l <= i:
                return True
        else:
            d[s[i:i+l]]=i
    return False def check(l):
    d = defaultdict(lambda: -1)
    for i in range(n-l+1):
        if d[s[i:i+l]] != -1:
            if d[s[i:i+l]] + l <= i:
                return True
        else:
            d[s[i:i+l]]=i
    return False check s=input() input() s mid=(ok+ng)//2 (ok+ng)//2 mid ng=len(s) len(s) ng
n=int(input())
s=input()

from collections import defaultdict

def check(l):
    d = defaultdict(lambda: -1)
    for i in range(n-l+1):
        if d[s[i:i+l]] != -1:
            if d[s[i:i+l]] + l <= i:
                return True
        else:
            d[s[i:i+l]]=i
    return False

ok=0
ng=len(s)

while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if check(mid):
        ok=mid
    else:
        ng=mid

print(ok)