N = gets.chomp.to_i
S = gets.chomp

dp = { 1 => {} }
N.times do |i|
  dp[1][S[i]] ||= []
  dp[1][S[i]] << i
end

max_k = 0

2.upto(N / 2) do |k|
  cont = false
  dp[k] = {}
  dp[k - 1].keys.each do |s|
    next if dp[k - 1][s].size < 2

    cont = true
    max_k = k - 1
    dp[k - 1][s].each do |i|
      next if i + k - 1 >= N
      ss = s + S[i + k - 1]
      dp[k][ss] ||= []
      dp[k][ss] << i
    end
  end
  max_k = k if dp[k].values.find {|vs| vs.size > 1 }
  break unless cont
end

puts max_k
