open Printf
open Scanf

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

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

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