let rec toSlim isDown tList fList =
    match fList with
    | [] -> tList |> List.rev
    | [ a ] -> toSlim isDown (a :: tList) []
    | a :: b :: from ->
        if a = b
           || (a > b && isDown)
           || (a < b && (not isDown)) then
            toSlim isDown tList (b :: from)
        else if a > b && (not isDown) then
            toSlim (not isDown) (a :: tList) (b :: from)
        else
            toSlim (not isDown) (a :: tList) (b :: from)

let rec solve money list =
    match list with
    | [] -> money
    | [ _ ] -> money
    | a :: b :: list ->
        let num = money / a
        let rest = money % a
        let gain = b * num
        solve (gain + rest) list

stdin.ReadLine()

stdin.ReadLine().Split(" ")
|> Array.map int
|> Array.toList
|> toSlim true []
|> solve 1000
|> printfn "%d"
