# frozen_string_literal: true

n = gets.to_i
s = gets.chomp.chars

def search(s, c, i)
  max = 0
  i.upto(s.size - 1) do |j|
    if s[j] == c
      count = 1
      k = i - 1
      loop do
        break if k + count >= j
        if s[k + count] == s[j + count]
          count += 1
        else
          max = count if max < count
          break
        end
      end
      max = count if max < count
    end
  end
  max
end

max = 0
0.upto(n - 1) do |i|
  count = search(s, s[i], i + 1)
  max = count if max < count
end

puts max
