def who_says_a_pun(n, s)
  dp = Array.new(n + 1) { Array.new(n + 1, 0) }
  (n - 1).downto(0) do |i|
    (n - 1).downto(0) do |j|
      if s[i] != s[j]
        dp[i][j] = 0
      else
        dp[i][j] = dp[i + 1][j + 1] + 1
      end
    end
  end

  ans = 0
  0.upto(n - 1) do |i|
    (i + 1).upto(n -1) do |j|
      now = [dp[i][j], j - i].min
      ans = [now, ans].max
    end
  end
  ans
end

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