import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


def z_algorithm(s):
    n = len(s)
    z = [0]*n
    z[0] = n
    i = 1
    j = 0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        z[i] = j

        if j==0:
            i+=1
            continue

        k = 1
        while k+z[k]<j:
            z[i+k] = z[k]
            k+=1
        
        i+=k
        j-=k
    
    return z

n = readint()
s = readstr()

ans = 0
for i in range(n):
    z = z_algorithm(s[i:])
    for j in range(n-i):
        if z[j]<=j:
            ans = max(ans,z[j])
print(ans)



 import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def readstr():return readline().rstrip().decode() readstr def readstrs():return list(readline().decode().split()) readstrs def readint():return int(readline()) readint def readints():return list(map(int,readline().split())) readints def printrows(x):print('\n'.join(map(str,x))) printrows x x def printline(x):print(' '.join(map(str,x))) printline x x def z_algorithm(s):
    n = len(s)
    z = [0]*n
    z[0] = n
    i = 1
    j = 0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        z[i] = j

        if j==0:
            i+=1
            continue

        k = 1
        while k+z[k]<j:
            z[i+k] = z[k]
            k+=1
        
        i+=k
        j-=k
    
    return z z_algorithm n = len(s) n len(s) len s z = [0]*n z [0]*n [0] 0 n z[0] = n z[0] z 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[i] = j

        if j==0:
            i+=1
            continue

        k = 1
        while k+z[k]<j:
            z[i+k] = z[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[i] = j z[i] z i j if j==0:
            i+=1
            continue

         j==0 j 0 i+=1 i 1 continue k = 1 k 1 while k+z[k]<j:
            z[i+k] = z[k]
            k+=1
        
         k+z[k]<j k+z[k] k z[k] z k j z[i+k] = z[k] z[i+k] z i+k i k z[k] z k k+=1 k 1 i+=k i k j-=k j k return z z s s n = readint() n readint() readint s = readstr() s readstr() readstr ans = 0 ans 0 for i in range(n):
    z = z_algorithm(s[i:])
    for j in range(n-i):
        if z[j]<=j:
            ans = max(ans,z[j]) i range(n) range n z = z_algorithm(s[i:]) z z_algorithm(s[i:]) z_algorithm s[i:] s i: i for j in range(n-i):
        if z[j]<=j:
            ans = max(ans,z[j]) j range(n-i) range n-i n i if z[j]<=j:
            ans = max(ans,z[j]) z[j]<=j z[j] z j j ans = max(ans,z[j]) ans max(ans,z[j]) max ans z[j] z j print(ans) print ans ans = max(ans,z[j]) max(ans,z[j]) ans def printrows(x):print('\n'.join(map(str,x))) def printrows(x):print('\n'.join(map(str,x))) printrows def readstrs():return list(readline().decode().split()) def readstrs():return list(readline().decode().split()) readstrs n = readint() readint() n z = z_algorithm(s[i:]) z_algorithm(s[i:]) z s = readstr() readstr() s def z_algorithm(s):
    n = len(s)
    z = [0]*n
    z[0] = n
    i = 1
    j = 0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        z[i] = j

        if j==0:
            i+=1
            continue

        k = 1
        while k+z[k]<j:
            z[i+k] = z[k]
            k+=1
        
        i+=k
        j-=k
    
    return z def z_algorithm(s):
    n = len(s)
    z = [0]*n
    z[0] = n
    i = 1
    j = 0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        z[i] = j

        if j==0:
            i+=1
            continue

        k = 1
        while k+z[k]<j:
            z[i+k] = z[k]
            k+=1
        
        i+=k
        j-=k
    
    return z z_algorithm readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline def printline(x):print(' '.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) printline def readints():return list(map(int,readline().split())) def readints():return list(map(int,readline().split())) readints def readstr():return readline().rstrip().decode() def readstr():return readline().rstrip().decode() readstr def readint():return int(readline()) def readint():return int(readline()) readint ans = 0 0 ans
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


def z_algorithm(s):
    n = len(s)
    z = [0]*n
    z[0] = n
    i = 1
    j = 0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        z[i] = j

        if j==0:
            i+=1
            continue

        k = 1
        while k+z[k]<j:
            z[i+k] = z[k]
            k+=1
        
        i+=k
        j-=k
    
    return z

n = readint()
s = readstr()

ans = 0
for i in range(n):
    z = z_algorithm(s[i:])
    for j in range(n-i):
        if z[j]<=j:
            ans = max(ans,z[j])
print(ans)




