--prewritten code: https://github.com/antma/algo
{-# LANGUAGE BangPatterns #-}
{-# Options_GHC -O2 #-}
import Data.ByteString.Builder
import Data.Monoid
import System.IO
import qualified Data.ByteString.Char8 as C
import Data.Char
import qualified Data.IntSet as S
import Data.List

ru, ri :: C.ByteString -> Int

ru = C.foldl' (\a c -> a * 10 - 48 + ord c) 0
ri s
  | C.head s == '-' = negate $ ru $ C.tail s
  | otherwise = ru s

solve :: [Int] -> Int
solve (n:b) = S.findMax s'
  where
    (x:y:t) = take n b
    (s', _) = foldl' (\ (st, g) !j -> (S.insert g $ S.map (gcd j) st, gcd g j)) (S.fromList [x, y], gcd x y) t  

main :: IO ()
main = print . solve . map ri . C.words =<< C.getContents
