### BUGGY CODE ###

N = int(input())
S = input()

hantei = False
ans = 0

isleft = True
kosu_original = N//4
if N > 2*10**5:
    for j in range(10):
        for i in range(N-kosu_original+1):
            temp = S[i:i+kosu_original]
            # print("比較する文字列1:", temp)
            # print("比較する文字列2:",S[0:i] + "|" + S[i+kosu_original:],"\n")
            if temp in S[0:i] + "|" + S[i+kosu_original:]:
                # print("Trueの時\n-----------------")
                ans = kosu_original
                isleft = False
                break
            if isleft:
                kosu_original //= 2
            else:
                kosu_original = (kosu_original + kosu_original*2)/2
                isleft = True

    if isleft:
        for kosu in range(kosu_original-1, 0, -1):
            if hantei:
                break

            for i in range(N-kosu+1):
                if hantei:
                    break
                else:
                    temp = S[i:i+kosu]
                    # print("比較する文字列1:", temp)
                    # print("比較する文字列2:",S[0:i] + "|" + S[i+kosu:],"\n")
                if temp in S[0:i] + "|" + S[i+kosu:]:
                    # print("Trueの時\n-----------------")
                    ans = kosu
                    hantei = True
                    break
    else:
        for kosu in range(N//2, kosu_original, -1):
            if hantei:
                break

            for i in range(N-kosu+1):
                if hantei:
                    break
                else:
                    temp = S[i:i+kosu]
                    # print("比較する文字列1:", temp)
                    # print("比較する文字列2:",S[0:i] + "|" + S[i+kosu:],"\n")
                if temp in S[0:i] + "|" + S[i+kosu:]:
                    # print("Trueの時\n-----------------")
                    ans = kosu
                    hantei = True
                    break
else:
    for i in range(N-kosu_original+1):
        temp = S[i:i+kosu_original]
        # print("比較する文字列1:", temp)
        # print("比較する文字列2:",S[0:i] + "|" + S[i+kosu_original:],"\n")
        if temp in S[0:i] + "|" + S[i+kosu_original:]:
            # print("Trueの時\n-----------------")
            ans = kosu_original
            isleft = False
            break

    if isleft:
        for kosu in range(kosu_original-1, 0, -1):
            if hantei:
                break

            for i in range(N-kosu+1):
                if hantei:
                    break
                else:
                    temp = S[i:i+kosu]
                    # print("比較する文字列1:", temp)
                    # print("比較する文字列2:",S[0:i] + "|" + S[i+kosu:],"\n")
                if temp in S[0:i] + "|" + S[i+kosu:]:
                    # print("Trueの時\n-----------------")
                    ans = kosu
                    hantei = True
                    break
    else:
        for kosu in range(N//2, kosu_original, -1):
            if hantei:
                break

            for i in range(N-kosu+1):
                if hantei:
                    break
                else:
                    temp = S[i:i+kosu]
                    # print("比較する文字列1:", temp)
                    # print("比較する文字列2:",S[0:i] + "|" + S[i+kosu:],"\n")
                if temp in S[0:i] + "|" + S[i+kosu:]:
                    # print("Trueの時\n-----------------")
                    ans = kosu
                    hantei = True
                    break

print(ans)


### FIXED CODE ###

def main():
    N = int(input())
    S = input()
    l1 = length = 0
    l2 = 1

    while (l2 + length < N):
        if S[l1:l2] in S[l2:]:
            length = l2 - l1
            l2 += 1
        else:
            l1 += 1
            l2 = l1 + length + 1
    print(length)

main()