n = gets.strip.to_i
s=gets.strip

max_l = n
min_l = 0

until min_l +1 == max_l
#p [min_l, max_l]
  l = (max_l+min_l+1)/2
  memo = {}
  ok = false
  (s.length-l+1).times do |i|
    k = s[i..i+l-1]
    if !memo[k].nil?
      if memo[k]+l-1 < i
        ok=true
        break
      end
    else
      memo[k]=i
    end
  end

  if ok
    min_l = l
  else
    max_l = l
  end

end

p min_l