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

def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    c = 0
    for i in range(1, n):
        if i + LCP[i-c] < c + LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and s[j] == s[i+j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP

ans = 0
for i in range(n):
    LCP = z_algorythm(s[i:])
    for j, l in enumerate(LCP):
        if j >= l:
            ans = max(ans, l)
print(ans) n = int(input()) n int(input()) int input() input s = input() s input() input def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    c = 0
    for i in range(1, n):
        if i + LCP[i-c] < c + LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and s[j] == s[i+j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP z_algorythm n = len(s) n len(s) len s LCP = [0]*n LCP [0]*n [0] 0 n c = 0 c 0 for i in range(1, n):
        if i + LCP[i-c] < c + LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and s[j] == s[i+j]:
                j += 1
            LCP[i] = j
            c = i
     i range(1, n) range 1 n if i + LCP[i-c] < c + LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and s[j] == s[i+j]:
                j += 1
            LCP[i] = j
            c = i
     i + LCP[i-c] < c + LCP[c] i + LCP[i-c] i LCP[i-c] LCP i-c i c c + LCP[c] c LCP[c] LCP c LCP[i] = LCP[i-c] LCP[i] LCP i LCP[i-c] LCP i-c i c j = max(0, c+LCP[c]-i) j max(0, c+LCP[c]-i) max 0 c+LCP[c]-i c+LCP[c] c LCP[c] LCP c i 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 LCP[i] = j LCP[i] LCP i j c = i c i LCP[0] = n LCP[0] LCP 0 n return LCP LCP s s ans = 0 ans 0 for i in range(n):
    LCP = z_algorythm(s[i:])
    for j, l in enumerate(LCP):
        if j >= l:
            ans = max(ans, l) i range(n) range n LCP = z_algorythm(s[i:]) LCP z_algorythm(s[i:]) z_algorythm s[i:] s i: i for j, l in enumerate(LCP):
        if j >= l:
            ans = max(ans, l) j l enumerate(LCP) enumerate LCP if j >= l:
            ans = max(ans, l) j >= l j l ans = max(ans, l) ans max(ans, l) max ans l print(ans) print ans ans = max(ans, l) max(ans, l) ans n = int(input()) int(input()) n s = input() input() s ans = 0 0 ans def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    c = 0
    for i in range(1, n):
        if i + LCP[i-c] < c + LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and s[j] == s[i+j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    c = 0
    for i in range(1, n):
        if i + LCP[i-c] < c + LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and s[j] == s[i+j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP z_algorythm LCP = z_algorythm(s[i:]) z_algorythm(s[i:]) LCP
n = int(input())
s = input()

def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    c = 0
    for i in range(1, n):
        if i + LCP[i-c] < c + LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and s[j] == s[i+j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP

ans = 0
for i in range(n):
    LCP = z_algorythm(s[i:])
    for j, l in enumerate(LCP):
        if j >= l:
            ans = max(ans, l)
print(ans)