

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

ans = 0
for i in range(1,n):
    chain = 0
    for j in range(n-i):
        if(s[j]==s[i+j]):
            chain+=1
            if(ans<chain):
                ans = min(chain,i)
                #print(ans,i,j)
        else:
            chain=0

print(ans) n = int(input()) n int(input()) int input() input s = input() s input() input ans = 0 ans 0 for i in range(1,n):
    chain = 0
    for j in range(n-i):
        if(s[j]==s[i+j]):
            chain+=1
            if(ans<chain):
                ans = min(chain,i)
                #print(ans,i,j)
        else:
            chain=0 i range(1,n) range 1 n chain = 0 chain 0 for j in range(n-i):
        if(s[j]==s[i+j]):
            chain+=1
            if(ans<chain):
                ans = min(chain,i)
                #print(ans,i,j)
        else:
            chain=0 j range(n-i) range n-i n i if(s[j]==s[i+j]):
            chain+=1
            if(ans<chain):
                ans = min(chain,i)
                #print(ans,i,j)
        else:
            chain=0 s[j]==s[i+j] s[j] s j s[i+j] s i+j i j chain+=1 chain 1 if(ans<chain):
                ans = min(chain,i)
                #print(ans,i,j)
         ans<chain ans chain ans = min(chain,i) ans min(chain,i) min chain i chain=0 chain 0 print(ans) print ans n = int(input()) int(input()) n ans = min(chain,i) min(chain,i) ans chain = 0 0 chain s = input() input() s chain+=1 1 chain ans = 0 0 ans chain=0 0 chain


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

ans = 0
for i in range(1,n):
    chain = 0
    for j in range(n-i):
        if(s[j]==s[i+j]):
            chain+=1
            if(ans<chain):
                ans = min(chain,i)
                #print(ans,i,j)
        else:
            chain=0

print(ans)