ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
def z_algo(s):
    ret = [0]*(len(s))
    ret[0] = len(s)
    i = 1
    j = 0
    while i<len(s):
        while i+j<len(s)  and s[i+j]==s[j]:
            j+=1
        ret[i] = j
        if j==0:
            i+=1
            continue
        k=1
        while i+k<len(s) and k+ret[k] <j:
            ret[i+k] = ret[k]
            k+=1
        i+=k
        j=min(ret[k],j-k) ## j= j-kでもよい
    return ret

n = ni()
s = input()
ans = 0
for i in range(n):
    z = z_algo(s[i:])
    for j in range(len(z)):
        if j>=z[j]:
            ans = max(ans,z[j])
print(ans) ma = lambda :map(int,input().split()) ma lambda :map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split lma = lambda :list(map(int,input().split())) lma lambda :list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split tma = lambda :tuple(map(int,input().split())) tma lambda :tuple(map(int,input().split())) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ni = lambda:int(input()) ni lambda:int(input()) int(input()) int input() input yn = lambda fl:print("Yes") if fl else print("No") yn lambda fl:print("Yes") if fl else print("No") print("Yes") if fl else print("No") fl print("Yes") print "Yes" print("No") print "No" fl import collections collections import math math import itertools itertools import heapq as hq heapq def z_algo(s):
    ret = [0]*(len(s))
    ret[0] = len(s)
    i = 1
    j = 0
    while i<len(s):
        while i+j<len(s)  and s[i+j]==s[j]:
            j+=1
        ret[i] = j
        if j==0:
            i+=1
            continue
        k=1
        while i+k<len(s) and k+ret[k] <j:
            ret[i+k] = ret[k]
            k+=1
        i+=k
        j=min(ret[k],j-k) ## j= j-kでもよい
    return ret z_algo ret = [0]*(len(s)) ret [0]*(len(s)) [0] 0 len(s) len s ret[0] = len(s) ret[0] ret 0 len(s) len s i = 1 i 1 j = 0 j 0 while i<len(s):
        while i+j<len(s)  and s[i+j]==s[j]:
            j+=1
        ret[i] = j
        if j==0:
            i+=1
            continue
        k=1
        while i+k<len(s) and k+ret[k] <j:
            ret[i+k] = ret[k]
            k+=1
        i+=k
        j=min(ret[k],j-k) ## j= j-kでもよい
     i<len(s) i len(s) len s while i+j<len(s)  and s[i+j]==s[j]:
            j+=1
         i+j<len(s)  and s[i+j]==s[j] i+j<len(s) i+j i j len(s) len s s[i+j]==s[j] s[i+j] s i+j i j s[j] s j j+=1 j 1 ret[i] = j ret[i] ret i j if j==0:
            i+=1
            continue
         j==0 j 0 i+=1 i 1 continue k=1 k 1 while i+k<len(s) and k+ret[k] <j:
            ret[i+k] = ret[k]
            k+=1
         i+k<len(s) and k+ret[k] <j i+k<len(s) i+k i k len(s) len s k+ret[k] <j k+ret[k] k ret[k] ret k j ret[i+k] = ret[k] ret[i+k] ret i+k i k ret[k] ret k k+=1 k 1 i+=k i k j=min(ret[k],j-k) j min(ret[k],j-k) min ret[k] ret k j-k j k return ret ret s s n = ni() n ni() ni s = input() s input() input ans = 0 ans 0 for i in range(n):
    z = z_algo(s[i:])
    for j in range(len(z)):
        if j>=z[j]:
            ans = max(ans,z[j]) i range(n) range n z = z_algo(s[i:]) z z_algo(s[i:]) z_algo s[i:] s i: i for j in range(len(z)):
        if j>=z[j]:
            ans = max(ans,z[j]) j range(len(z)) range len(z) len z if j>=z[j]:
            ans = max(ans,z[j]) j>=z[j] j z[j] z j ans = max(ans,z[j]) ans max(ans,z[j]) max ans z[j] z j print(ans) print ans ma = lambda :map(int,input().split()) lambda :map(int,input().split()) ma lma = lambda :list(map(int,input().split())) lambda :list(map(int,input().split())) lma tma = lambda :tuple(map(int,input().split())) lambda :tuple(map(int,input().split())) tma yn = lambda fl:print("Yes") if fl else print("No") lambda fl:print("Yes") if fl else print("No") yn z = z_algo(s[i:]) z_algo(s[i:]) z s = input() input() s ni = lambda:int(input()) lambda:int(input()) ni ans = 0 0 ans n = ni() ni() n def z_algo(s):
    ret = [0]*(len(s))
    ret[0] = len(s)
    i = 1
    j = 0
    while i<len(s):
        while i+j<len(s)  and s[i+j]==s[j]:
            j+=1
        ret[i] = j
        if j==0:
            i+=1
            continue
        k=1
        while i+k<len(s) and k+ret[k] <j:
            ret[i+k] = ret[k]
            k+=1
        i+=k
        j=min(ret[k],j-k) ## j= j-kでもよい
    return ret def z_algo(s):
    ret = [0]*(len(s))
    ret[0] = len(s)
    i = 1
    j = 0
    while i<len(s):
        while i+j<len(s)  and s[i+j]==s[j]:
            j+=1
        ret[i] = j
        if j==0:
            i+=1
            continue
        k=1
        while i+k<len(s) and k+ret[k] <j:
            ret[i+k] = ret[k]
            k+=1
        i+=k
        j=min(ret[k],j-k) ## j= j-kでもよい
    return ret z_algo ans = max(ans,z[j]) max(ans,z[j]) ans
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
def z_algo(s):
    ret = [0]*(len(s))
    ret[0] = len(s)
    i = 1
    j = 0
    while i<len(s):
        while i+j<len(s)  and s[i+j]==s[j]:
            j+=1
        ret[i] = j
        if j==0:
            i+=1
            continue
        k=1
        while i+k<len(s) and k+ret[k] <j:
            ret[i+k] = ret[k]
            k+=1
        i+=k
        j=min(ret[k],j-k) ## j= j-kでもよい
    return ret

n = ni()
s = input()
ans = 0
for i in range(n):
    z = z_algo(s[i:])
    for j in range(len(z)):
        if j>=z[j]:
            ans = max(ans,z[j])
print(ans)
