import collections
n,s = int(raw_input()), raw_input()

def f(k, s):	
 	cc,q = collections.Counter(), collections.deque()
	for j in range(k - 1, len(s)):
		q.append(s[j - k + 1:j+1])
		if len(q) == k + 1: cc[q.popleft()] += 1
		if q[-1] in cc: return True	
	return False

lo,hi = 0, n/2
while(lo < hi):
	med = (lo + hi + 1) / 2
	if f(med, s):  lo = med
	else:hi = med - 1
print lo import collections collections n,s = int(raw_input()), raw_input() n int(raw_input()) int raw_input() raw_input s raw_input() raw_input def f(k, s):	
 	cc,q = collections.Counter(), collections.deque()
	for j in range(k - 1, len(s)):
		q.append(s[j - k + 1:j+1])
		if len(q) == k + 1: cc[q.popleft()] += 1
		if q[-1] in cc: return True	
	return False f cc,q = collections.Counter(), collections.deque() cc collections.Counter() collections.Counter collections Counter q collections.deque() collections.deque collections deque for j in range(k - 1, len(s)):
		q.append(s[j - k + 1:j+1])
		if len(q) == k + 1: cc[q.popleft()] += 1
		if q[-1] in cc: return True	
	 j range(k - 1, len(s)) range k - 1 k 1 len(s) len s q.append(s[j - k + 1:j+1]) q.append q append s[j - k + 1:j+1] s j - k + 1:j+1 j - k + 1 j - k j k 1 j+1 j 1 if len(q) == k + 1: cc[q.popleft()] += 1
		 len(q) == k + 1 len(q) len q k + 1 k 1 if q[-1] in cc: return True	
	 q[-1] in cc q[-1] q -1 cc return False False k k s s lo,hi = 0, n/2 lo 0 hi n/2 n 2 while(lo < hi):
	med = (lo + hi + 1) / 2
	if f(med, s):  lo = med
	else:hi = med - 1 lo < hi lo hi med = (lo + hi + 1) / 2 med (lo + hi + 1) / 2 lo + hi + 1 lo + hi lo hi 1 2 if f(med, s):  lo = med
	else:hi = med - 1 f(med, s) f med s print lo,hi = 0, n/2 0 lo s = int(raw_input()), raw_input() raw_input() s n,s = int(raw_input()), raw_input() int(raw_input()) n hi = 0, n/2 n/2 hi def f(k, s):	
 	cc,q = collections.Counter(), collections.deque()
	for j in range(k - 1, len(s)):
		q.append(s[j - k + 1:j+1])
		if len(q) == k + 1: cc[q.popleft()] += 1
		if q[-1] in cc: return True	
	return False def f(k, s):	
 	cc,q = collections.Counter(), collections.deque()
	for j in range(k - 1, len(s)):
		q.append(s[j - k + 1:j+1])
		if len(q) == k + 1: cc[q.popleft()] += 1
		if q[-1] in cc: return True	
	return False f med = (lo + hi + 1) / 2 (lo + hi + 1) / 2 med
import collections
n,s = int(raw_input()), raw_input()

def f(k, s):	
 	cc,q = collections.Counter(), collections.deque()
	for j in range(k - 1, len(s)):
		q.append(s[j - k + 1:j+1])
		if len(q) == k + 1: cc[q.popleft()] += 1
		if q[-1] in cc: return True	
	return False

lo,hi = 0, n/2
while(lo < hi):
	med = (lo + hi + 1) / 2
	if f(med, s):  lo = med
	else:hi = med - 1
print lo