import java.util.*
class RollingHash(val N:Int,val S:String){
  val base = 101L
  val mod = 100000000003L
  val powBase = Array(N){1L}
  init{
    for(i in 1 until N){
      powBase[i] = powBase[i-1]*base%mod
    }
  }
  fun check(len:Int):Boolean{
    val T = TreeMap<Long,Int>()
    var hash = 0L
    for(i in 0 until len){
      hash = (hash + S[i].toLong()*powBase[len-i-1])%mod
    }
    T.put(hash,-1)
    for(i in 0 until N-len){
      hash = (hash - S[i].toLong()*powBase[len-1])*base+S[i+len].toLong()
      hash = hash%mod
      hash = if(hash>=0)hash else hash+mod
      if(T.containsKey(hash)){
        if(i-T[hash]!!>=len){
          return true
        }
      }
      else
      {
        T.put(hash,i)
      }
    }
    return false
 }
  fun maxlen():Int{
    var left = 0
    var right = N/2.toInt()+1
    while(right-left>1){
      val len = (right+left)/2.toInt()
      if(check(len))left = len else right = len
    }
    return left
  }
}
fun main(args:Array<String>){
  val rh = RollingHash(readLine()!!.toInt(),readLine()!!)
  println(rh.maxlen())
}
