let solve c n m =
  let dp = Array.make_matrix (m + 1) (n + 1) max_int in
  for i = 1 to m do dp.(i).(0) <- 0 done;
  for i = 1 to m do
    for j = 1 to n do
      dp.(i).(j) <-
        if j - c.(i-1) < 0 then dp.(i-1).(j)
        else min dp.(i-1).(j) (dp.(i).(j - c.(i-1)) + 1)
    done
  done;
  dp.(m).(n)

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