B1 = 100000007
B2 = 1000000007
MAP = ["","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
def rolling_hash(s,t_start,m)
  s_start = t_start + m
  pow_b_m_1,pow_b_m_2 = 1,1
  for i in 0..(m-1)
    pow_b_m_1 *= B1
    pow_b_m_2 *= B2
  end
  sh1,sh2,th1,th2 = 0,0,0,0
  for i in 0..(m-1)
    th1 = th1 * B1 + MAP.find_index(s[t_start+i])
    th2 = th2 * B2 + MAP.find_index(s[t_start+i])
    sh1 = sh1 * B1 + MAP.find_index(s[s_start+i])
    sh2 = sh2 * B2 + MAP.find_index(s[s_start+i])
  end
  for i in 0..(s.length-s_start-1)
    if sh1 == th1 && sh2 == th2
      return true
    end
    if i + s_start < s.length
      sh1 = sh1 * B1 + MAP.find_index(s[(s_start+m+i)%s.length]) - MAP.find_index(s[s_start+i]) * pow_b_m_1
      sh2 = sh2 * B2 + MAP.find_index(s[(s_start+m+i)%s.length]) - MAP.find_index(s[s_start+i]) * pow_b_m_2
    end
  end
  return false
end
n = gets.to_i
s = gets.chomp
ng = n+1
ok = 0
while ng - ok > 1
  mid = (ng + ok) / 2
  mached = false
  for i in 0..(n-1)
    if i+mid*2 > n
      break
    end
    if rolling_hash(s,i,mid)
      mached = true
      break
    end
  end
  if mached
    ok = mid
  else
    ng = mid
  end
end
puts ok