let change n m d =
  let t = Array.make (n + 1) max_int in
  let rec doit = function
    | (i, _) when i = m -> t.(n)
    | (i, x) when x + d.(i) > n -> doit (i + 1, 0)
    | (i, x) ->
      t.(x + d.(i)) <-
        if t.(x + d.(i)) < t.(x) + 1 then t.(x + d.(i))
        else t.(x) + 1;
      doit (i, x + 1) in
  t.(0) <- 0;
  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
  Printf.printf "%d\n" (change n m d)