open Printf
open Scanf

let n = scanf "%d\n" (fun n -> n)
let alist = Array.init n (fun _ -> scanf " %d" (fun a -> a))

let ary = Array.make (n + 1) 0

let rec solve d kane kabu kabuka =
    if d >= n then kane
    else begin
        let kabu' = kane / alist.(d) in
        if kabuka >= alist.(d) then begin
            let kane' = kane - kabu' * alist.(d) in
            let kau = solve (d + 1) kane' kabu' alist.(d) in
            let kawanai = solve (d + 1) kane kabu kabuka in
            max kau kawanai
        end else if kabu > 0 && kabuka < alist.(d) then begin
            let kane' = kane + kabu * alist.(d) in
            let uru = solve (d + 1) kane' 0 alist.(d) in
            let uranai = solve (d + 1) kane kabu kabuka in
            max uru uranai
        end else
            solve (d + 1) kane kabu kabuka
    end

let () = printf "%d\n" (solve 0 1000 0 alist.(0))
