n = gets.chomp.to_i
s = gets.chomp
maxn = n/2
ans = 0
finish = false
nn = n-1
maxn.downto(1) do |ni|
  0.upto(n-ni-ni) do |nii|
    if /#{s[nii..(nii+ni-1)]}/.match( s[(nii+ni)..(nn)])
      ans = ni
      finish = true
      break
    end
  end
  break if finish
end

puts ans
