import math

n = int(eval(input()))

s = eval(input())

ans=0

for i in range(n):

    #print(i,n)

    maxim = i

    num=[0 for k in range(n-i)]

    count=0

    lmax=0

    for j in range(n-i):

        if(s[j]==s[i+j]):

            num[j]=1

            count+=1

            #print(count)

            if(lmax<count):

                lmax=count

        else:

            count=0

    #print(lmax)

    if(ans<lmax):

        ans=min(lmax,maxim)

print(ans)

        




n = int(eval(input()))

s = eval(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)
import math

n = int(eval(input()))
s = eval(input())
ans = 0
for i in range(n):
    # print(i,n)
    maxim = i
    num = [0 for k in range(n - i)]
    count = 0
    lmax = 0
    for j in range(n - i):
        if s[j] == s[i + j]:
            num[j] = 1
            count += 1
            # print(count)
            if lmax < count:
                lmax = count
        else:
            count = 0
    # print(lmax)
    if ans < lmax:
        ans = min(lmax, maxim)
print(ans)

n = int(eval(input()))
s = eval(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)

-import math - -for i in range(n): -    # print(i,n) -    maxim = i -    num = [0 for k in range(n - i)] -    count = 0 -    lmax = 0 +for i in range(1, n): +    chain = 0 -            num[j] = 1 -            count += 1 -            # print(count) -            if lmax < count: -                lmax = count +            chain += 1 +            if ans < chain: +                ans = min(chain, i) +                # print(ans,i,j) -            count = 0 -    # print(lmax) -    if ans < lmax: -        ans = min(lmax, maxim) +            chain = 0