import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
object Main extends App {
  import scala.io.StdIn._
  val n = readInt
  val numbers = readLine.trim.split(' ').map(_.toInt)
  val indices = numbers.indices.groupBy(numbers).toArray.map(_._2.sorted.toArray)
  val longest = indices.map(_.length).foldLeft(n)(gcd)
  println(Some((2 to longest).filter(k ⇒ n % k == 0).filter{k ⇒
    val t = n / k
    indices.forall{index ⇒
      binarySearch(index, index.head + t) match {
        case Some(j) ⇒ (0 until index.length - j).forall(i ⇒ index(i) + t == index(i + j))
        case None ⇒ false
      }
    }
  }).filter(_.nonEmpty).getOrElse(List(1)).reduce(lcm))
  def lcm(a: Int, b: Int): Int = a / gcd(a, b) * b
  @tailrec def gcd(a: Int, b: Int): Int =  b match {
    case 0 ⇒ a
    case _ ⇒ gcd(b, a % b)
  }
  def binarySearch(array: Array[Int], target: Int): Option[Int] = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) < target) left = mid + 1
      else right = mid
    }
    if (right < array.length && array(right) == target) Some(right)
    else None
  }
}
