//object ABC141EJvm {
object Main {

  def main(args: Array[Int]): Unit = println(solve(parse()))

  def solve(input: (Int, Int, List[Int])): Int = {
    val (n, m, an) = input
    val maxSubStringLength = an.length / 2 - (if (an.length % 2 == 0) 1 else 0)
    val r = (1 to maxSubStringLength).reverse.find { i =>
      (0 until i).exists { j =>
        val slicedString = an.slice(j, j + i)
        (an.take(j) ++ an.drop(j + i)).contains(slicedString)
      }
    }.toList
    if (r.isEmpty) 0 else r.max
  }

  def parse(): (Int, Int, List[Int]) = {
    val input: List[List[Int]] = io.Source.stdin.getLines().map(_.map(_.toInt).toList).toList
    val n :: k :: Nil = input.head
    val _ :: an :: Nil = input
    (n, k, an)
  }
}
