def isSubstring(n,s,i)
  flg = false
  for j in 0..n-i*2
    str = s[j..j+i-1]
    for k in j+i..n-i
      if str == s[k..k+i-1]
        flg = true
      end
    end
  end
  flg
end

n = gets.to_i
s = gets.chomp
i = n / 2
range = i
ans = 0
while range != 0
  if isSubstring(n,s,i)
    range = range / 2
    ans = i
    i += range
  else
    range = range / 2
    i -= range
  end
end
if isSubstring(n,s,i-1)
  ans = ans > i-1 ? ans : i-1
end
if isSubstring(n,s,i+1)
  ans = i+1
end

puts ans