let rec read f n =
  if n <= 0 then []
  else
    let x = f () in
    x :: read f (n - 1)

let () =
  let n = read_int () in
  let ls = read read_int n in
  let tbl = Array.make_matrix 101 10001 false in
  let rec loop i xs =
    let rec iloop j v =
      if j > 10000 then () else begin
          if tbl.(i).(j) then begin
              tbl.(i+1).(j) <- true;
              tbl.(i+1).(j+v) <- true
            end else ();
          iloop (j+1) v
        end
    in
    match xs with
      [] -> ()
    | h :: l -> begin
        iloop 0 h;
        loop (i+1) l
      end
  in
  let rec find i =
    if i = 0 then 0 else
      if tbl.(n).(i) then
        if i mod 10 = 0 then find (i-1) else i
      else
        find (i-1)
  in
  tbl.(0).(0) <- true;
  loop 0 ls;
  find 10000 |> string_of_int |> print_endline
