def find_substring(n, s, l)
  return false if l.zero?
  0.upto(n - l * 2) do |i|
    (i + l).upto(n - l) do |j|
      return true if s[i...(i + l)] == s[j...(j + l)]
    end
  end
  false
end

def who_says_a_pun(n, s)
  left = 0
  right = n / 2 + 1
  while left < right
    mid = (left + right) / 2
    if find_substring(n, s, mid)
      left = mid + 1
    else
      right = mid
    end
  end
  
  [left - 1, 0].max
end

n = gets.to_i
s = gets.chomp
puts who_says_a_pun(n, s)