n = gets.to_i
s = gets.chomp
max = 0
1.upto(n/2) do |i|
  pre = max
  (n-i-i+1).times do |j|
    if s[j+i..-1][s[j..(j+i-1)]]
      max = i if max < i
      break
    end
  end
  if max == pre
    break
  end
end
puts max