import Data.List
import Data.Array
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Control.Monad
import Control.Monad.State
import Control.Monad.ST
import Debug.Trace

next :: [Int] -> Int
next [x] = x
next ls = next $ insert (head $ sort ls) $ filter (/=0) $ map (`mod`(head $ sort ls)) (tail $ sort ls)

main :: IO ()
main = do
  _ <- read <$> getLine :: IO Int
  ls <- map read.words <$> getLine
  putStrLn $ show $ next ls
