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

def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg
ans=0
for i in range(n):
    t=s[i:]
    z=Z_algorithm(t)
    ans=max(ans,max([min(j,z[j]) for j in range(len(z))]))

print(ans) n=int(input()) n int(input()) int input() input s=input() s input() input def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg Z_algorithm N = len(s) N len(s) len s Z_alg = [0]*N Z_alg [0]*N [0] 0 N Z_alg[0] = N Z_alg[0] Z_alg 0 N i = 1 i 1 j = 0 j 0 while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
     i < N i N while i+j < N and s[j] == s[i+j]:
            j += 1
         i+j < N and s[j] == s[i+j] i+j < N i+j i j N s[j] == s[i+j] s[j] s j s[i+j] s i+j i j j += 1 j 1 Z_alg[i] = j Z_alg[i] Z_alg i j if j == 0:
            i += 1
            continue
         j == 0 j 0 i += 1 i 1 continue k = 1 k 1 while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
         i+k < N and k + Z_alg[k]<j i+k < N i+k i k N k + Z_alg[k]<j k + Z_alg[k] k Z_alg[k] Z_alg k j Z_alg[i+k] = Z_alg[k] Z_alg[i+k] Z_alg i+k i k Z_alg[k] Z_alg k k += 1 k 1 i += k i k j -= k j k return Z_alg Z_alg s s ans=0 ans 0 for i in range(n):
    t=s[i:]
    z=Z_algorithm(t)
    ans=max(ans,max([min(j,z[j]) for j in range(len(z))])) i range(n) range n t=s[i:] t s[i:] s i: i z=Z_algorithm(t) z Z_algorithm(t) Z_algorithm t min(j,z[j]) for j in range(len(z)) for j in range(len(z)) j range(len(z)) range len(z) len z for j in range(len(z)) min(j,z[j]) min j z[j] z j ans=max(ans,max([min(j,z[j]) for j in range(len(z))])) ans max(ans,max([min(j,z[j]) for j in range(len(z))])) max ans max([min(j,z[j]) for j in range(len(z))]) max [min(j,z[j]) for j in range(len(z))] print(ans) print ans n=int(input()) int(input()) n t=s[i:] s[i:] t z=Z_algorithm(t) Z_algorithm(t) z ans=0 0 ans ans=max(ans,max([min(j,z[j]) for j in range(len(z))])) max(ans,max([min(j,z[j]) for j in range(len(z))])) ans def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg Z_algorithm s=input() input() s
n=int(input())
s=input()

def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg
ans=0
for i in range(n):
    t=s[i:]
    z=Z_algorithm(t)
    ans=max(ans,max([min(j,z[j]) for j in range(len(z))]))

print(ans)