import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

calc :: Int -> [Int] -> Int -> Int
calc m [] s = s
calc m (a : as) s = calc m as (s + m `mod` a)

main = do
  n <- getInt
  as <- getIntList
  print $ maximum (map (\m -> calc m as 0) [2 .. 3000])
