n = gets.to_i
s = gets.chomp

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

if results.length > 0
	print(results.max)
else
	print(0)
end
