let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a
  in
  let (prev, (incr, decr), (stock, yen)) =
    Array.fold_left (fun (prev, (incr, decr), (stock, yen)) a ->
      a, (if a = prev then (incr, decr) else (prev < a, a < prev)),
      if not decr && a < prev
      then (0, prev * stock + yen)
      else if not incr && prev < a
      then (stock + yen / prev, yen mod prev)
      else (stock, yen)) (as_.(0), (false, false), (0, 1000)) as_ in
  Printf.printf "%d\n" @@ prev * stock + yen