import io.StdIn

object Main extends App {

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

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

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

  println(ans)
}
