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

		while s[i, j] == s[s.index(tmp, i + 1), j]
			if i + j + 2 < n
				tmp = s[i, j]
			end
			j = j + 1
		end
		max = tmp.length
		j = j + 1
	end
	i = i + 1
end
print(max)