n = gets.strip.to_i
ss=gets.strip

min_l = 0
max_l = n

until min_l+1==max_l
  l = (min_l+max_l)/2
#p [l, min_l, max_l]
  memo = {}
  ok = false
  0.upto(n-l) do |i|
    k=ss[i...i+l]
    if memo[k]
      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
