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

tmp = 0
for i in range(n-1):
	for j in range(i+tmp+1, n):
		if not s[i:j] in s[j:]:
			break
	tmp = max(tmp, j-i-1)

"""
二重ループ型だが実際はO(ans N)でうごく.
"""

print(tmp) n = int(input()) n int(input()) int input() input s = input() s input() input tmp = 0 tmp 0 for i in range(n-1):
	for j in range(i+tmp+1, n):
		if not s[i:j] in s[j:]:
			break
	tmp = max(tmp, j-i-1) i range(n-1) range n-1 n 1 for j in range(i+tmp+1, n):
		if not s[i:j] in s[j:]:
			break
	 j range(i+tmp+1, n) range i+tmp+1 i+tmp i tmp 1 n if not s[i:j] in s[j:]:
			break
	 not s[i:j] in s[j:] s[i:j] in s[j:] s[i:j] s i:j i j s[j:] s j: j break tmp = max(tmp, j-i-1) tmp max(tmp, j-i-1) max tmp j-i-1 j-i j i 1 """
二重ループ型だが実際はO(ans N)でうごく.
""" print(tmp) print tmp tmp = 0 0 tmp s = input() input() s n = int(input()) int(input()) n tmp = max(tmp, j-i-1) max(tmp, j-i-1) tmp
n = int(input())
s = input()

tmp = 0
for i in range(n-1):
	for j in range(i+tmp+1, n):
		if not s[i:j] in s[j:]:
			break
	tmp = max(tmp, j-i-1)

"""
二重ループ型だが実際はO(ans N)でうごく.
"""

print(tmp)