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
    if s[i..s.length].include?(s[j..i-1])
      res = i
      break
    end
    j += 1
  end
  break if res > 0
  i -= 1
end

puts res
