
let rec gain money fList =
    match fList with
    | [] -> money
    | [ _ ] -> money
    | (a :: b :: fList) ->
        if a < b then
            let num = a % money
            let newMoney = money + (b - a) * num
            gain newMoney (b :: fList)
        else
            gain money (b :: fList)


stdin.ReadLine()

stdin.ReadLine().Split(" ")
|> Array.map int
|> Array.toList
|> gain 1000
|> printfn "%d"
