let change n m d =
  let t = Array.make (n + 1) max_int in
  t.(0) <- 0;
  let rec doit i x =
    if i = m then t.(n)
    else
      let v = x + d.(i) in
      if v > n then doit (i + 1) 0
      else begin
        t.(v) <- min t.(v) (t.(x) + 1);
        doit i (x + 1)
      end in
  doit 0 0

let () =
  let (n, m) = Scanf.scanf "%d %d " (fun n m -> (n, m)) in
  let d = Array.init m (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  change n m d |> Printf.printf "%d\n"