main = do
  getLine
  as<-map read.words<$>getLine
  print $ solve as

solve :: [Int]->Int
solve as
  | length sames == length as  = head sames
  | length sames == length as -1 = head sames
  | otherwise = product $ map (uncurry(^)) factors
  where
  sames = filter (/= -1) $ zipWith(\a b->if a==b then a else -1)as (tail as++[head as])
  factors = map f (take 10000 primes)
  f p = (p, min2 $ map (ex p) as)
  ex p n
    | n `mod` p == 0 = 1 + ex p (n `div` p)
    | otherwise = 0
  min2 :: [Int]->Int
  min2 = snd . go (maxBound,maxBound)
    where
    go (f,s) [] = (f,s)
    go (f,s) (n:ns)
      | n<f = go (n,f) ns
      | n<s = go (f,n) ns
      | otherwise = go (f,s) ns

primes = map fromIntegral $ [2, 3] ++ primes'
    where
      primes' = 5 : f 1 7 primes'
      f m s (p : ps) = [n | n <- ns, gcd m n == 1] ++ f (m * p) (p * p) ps
          where ns = [x + y | x <- [s, s + 6 .. p * p - 2], y <- [0, 4]]