def calc(z)
  len = z.length
  max = 0
  for i in 1..len-1
    ans = z[i] > i ? i : z[i]
    max = ans > max ? ans : max
  end
  max
end

n = gets.to_i
s = gets.chomp
max = 0
for i in 0..n-1
  str = s[i..n-1]
  len = n-i
  z = []
  z[0] = len
  j = 1
  k = 0
  while j < len
    while j+k < len && str[k] == str[j+k]
      k+=1
    end
    z[j] = k
    if k == 0
      j += 1
    else
      l = 1
      while j+l < len && l+z[l] < k
        z[j+l] = z[l]
        l += 1
      end
      j += l
      k -= l
    end
  end
  tmp = calc(z)
  max = tmp > max ? tmp : max
end

puts max