n = gets.to_i
s = gets.chomp

max = 0
i = 0
j = 1
while i < n
	while j < n - i
		if (i + j * 2) > n
			break
		end
		tmp = s[i, j]
		if 2 > s.scan(/#{tmp}/).length
			break
		end
		max = tmp.length
		j = j + 1
	end
	i = i + 1
end
print(max)