n = gets.to_i
s = gets.chomp
 
i = n/2
 
res = 0
while i > 0 do
  j = 0
  while s.length - ( j + i ) >= i do
    return puts i if s[i..s.length].include?(s[j..i-1])
    j += 1
  end
  i -= 1
end

puts 0