import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  var S = in.next()

  //
  var ans = 0
  for (i <- 0 until N) {
    val zal = new ZAlgorithm(S)
    val Z = zal.Z
    for (j <- 1 until N-i) {
      ans = Math.max(ans, j min Z(j))
    }

    if (!S.isEmpty)
      S = S.tail
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

// O(|S|)
class ZAlgorithm(S: String) {
  private[this] val N = S.length

  // Z配列
  val Z = new Array[Int](N)

  Z(0) = N
  private[this] var i = 1
  private[this] var j = 0
  while (i < N) {
    while (i + j < N && S(j) == S(i+j))
      j += 1
    Z(i) = j

    if (j == 0) {
      i += 1
    }
    else {
      var k = 1
      while (k < j && k + Z(k) < j) {
        Z(i+k) = Z(k)
        k += 1
      }
      i += k
      j -= k
    }
  }
}
