object Main extends App {

  val Array(n, m) = io.StdIn.readLine.split(" ").map(_.toInt)
  val c = io.StdIn.readLine.split(" ").map(_.toInt)

  val ans = {
    val dp: Array[Int] = Array.fill[Int](n + 1)(Int.MaxValue)
    dp(0) = 0

    for {
      i <- 0 until m
      j <- c(i) to n
    } dp(j) = math.min(dp(j), dp(j - c(i)) + 1)

    dp(n)
  }

  println(ans)
}
