import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = LS2()


def Z_algorithm(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i,j = 1,0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        # S[0:j] == S[i:i+j] となっている
        A[i] = j
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A


ans = 0
for i in range(N):
    A = Z_algorithm(S)
    for j in range(N-i):
        if A[j] <= j:
            ans = max(ans,A[j])
    del S[0]

print(ans) import sys sys def I(): return int(sys.stdin.readline().rstrip()) I def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし LS2 N = I() N I() I S = LS2() S LS2() LS2 def Z_algorithm(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i,j = 1,0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        # S[0:j] == S[i:i+j] となっている
        A[i] = j
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A Z_algorithm N = len(S) N len(S) len S A = [0]*N A [0]*N [0] 0 N A[0] = N A[0] A 0 N i,j = 1,0 i 1 j 0 while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        # S[0:j] == S[i:i+j] となっている
        A[i] = j
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[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 if j == 0:
            i += 1
            continue
        # S[0:j] == S[i:i+j] となっている
         j == 0 j 0 i += 1 i 1 continue A[i] = j A[i] A i j k = 1 k 1 while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
         i+k < N and k+A[k] < j i+k < N i+k i k N k+A[k] < j k+A[k] k A[k] A k j A[i+k] = A[k] A[i+k] A i+k i k A[k] A k k += 1 k 1 i += k i k j -= k j k return A A S S ans = 0 ans 0 for i in range(N):
    A = Z_algorithm(S)
    for j in range(N-i):
        if A[j] <= j:
            ans = max(ans,A[j])
    del S[0] i range(N) range N A = Z_algorithm(S) A Z_algorithm(S) Z_algorithm S for j in range(N-i):
        if A[j] <= j:
            ans = max(ans,A[j])
     j range(N-i) range N-i N i if A[j] <= j:
            ans = max(ans,A[j])
     A[j] <= j A[j] A j j ans = max(ans,A[j]) ans max(ans,A[j]) max ans A[j] A j del S[0] S[0] S 0 print(ans) print ans def Z_algorithm(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i,j = 1,0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        # S[0:j] == S[i:i+j] となっている
        A[i] = j
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A def Z_algorithm(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i,j = 1,0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        # S[0:j] == S[i:i+j] となっている
        A[i] = j
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A Z_algorithm ans = max(ans,A[j]) max(ans,A[j]) ans def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし LS2 ans = 0 0 ans A = Z_algorithm(S) Z_algorithm(S) A def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I S = LS2() LS2() S N = I() I() N
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = LS2()


def Z_algorithm(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i,j = 1,0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        # S[0:j] == S[i:i+j] となっている
        A[i] = j
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A


ans = 0
for i in range(N):
    A = Z_algorithm(S)
    for j in range(N-i):
        if A[j] <= j:
            ans = max(ans,A[j])
    del S[0]

print(ans)
