n = gets.to_i
s = gets.chomp

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