n = gets.to_i
s = gets.chomp
(1..(n / 2)).to_a.reverse_each do |j|
  map = Hash.new{[]}
  (0...n).each do |i|
    next if i + j > n
    key = s.slice(i, j)
    map[key] = map[key].push([i, j])
  end
  map.each do |_, v|
    next if v.count <= 1
    prev = v.first
    v.each do |k|
      prev_sum = prev[0] + prev[1]
      cur_sum = k[0] + k[1]
      if cur_sum - prev_sum >= j
        puts j
        exit 0
      end
      prev = k
    end
  end
end
puts 0