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

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

  val N = in.next().toInt
  private[this] val S = "0" + in.next()


  //
  private[this] def check(len: Int): Boolean = {
    val d: Map[String, Int] = Map()

    var flag = false
    breakable {
      for (i <- 1 to N-(len-1)) {
        val now = S.substring(i, i+len)
        if (d.contains(now)){
          if (i >= d(now)+len) {
            flag = true
            break
          }
        }
        else {
          d(now) = i
        }
      }
    }
    flag
  }

  // 条件を満たす最大の値を返す
  private[this] def binarySearch(min: Int, max: Int): Int = {
    val mid: Int = (max + min) / 2
      (max - min) match{
      case 0 | 1 =>
        check(max) match{
          case true  => max
          case false => min
        }
      case _ =>
        (check(mid)) match{
          case true  => binarySearch(mid, max)
          case false => binarySearch(min, mid)
        }
    }
  }

  val ans = binarySearch(0, N/2)
  println(ans)
}


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()
  }
}
