N = gets.to_i
S = gets.chomp

def f(len)
  list = Hash.new { |h, k| h[k] = [] }

  0.upto(N - len) do |i|
    str = S[i...i + len]
    list[str] << i
  end

  list.each do |str, points|
    min, max = points.minmax

    return true if max - min >= len
  end

  false
end

if !f(1)
  puts 0
  exit
end

ok = 1
ng = N

while ng - ok > 1
  mid = (ng + ok) / 2

  if f(mid)
    ok = mid
  else
    ng = mid
  end
end

puts ok
