def kmp_table(query)
  table = Array.new(query.size, nil)
  i = 2; j = 0
  table[0] = -1; table[1] = 0
  while i < query.size do
    if query[i-1] == query[j]
      table[i] = j+1
      i += 1
      j += 1
    elsif j > 0
      j = table[j]
    else
      table[i] = 0
      i += 1
    end
  end 
  table
end

def kmp(query, text)
  # retval == |query| -> complete match
  m = 0
  i = 0
  table = kmp_table(query)
  ans = 0
  while m+i < text.size do
    if query[i] == text[m+i]
      i += 1
      ans = i if i > ans
      if i == query.size
        return ans
      end
    else
      m += i - table[i]
      if i > 0
        i = table[i]
      end
    end
  end
  ans
end

N = gets.to_i
S = gets.chomp
ans = 0
(0...N-1).each{ |i|
  m = (N-i)/2
  break if ans >= m
  v = kmp(S[i...i+m], S[i+m..-1])
  ans = v if v > ans
}
p ans
