object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(n, m) = readLine().split(' ').map(_.toInt)
    val coin = readLine().split(' ').map(_.toInt).sorted.reverse.toList

    val memo = Array.fill(n + 1, m + 1)(-1)

    def solve(money: Int, coin: List[Int], coinLength: Int): Int = {
      if (coinLength == 1) { // 1円しか残っていない時
        money
      } else if (memo(money)(coinLength) != -1) {
        memo(money)(coinLength)
      } else {
        val result = List(
          solve(money, coin.tail, coinLength - 1),
          if (money < coin.head) Int.MaxValue else 1 + solve(money - coin.head, coin, coinLength)
        ).min
        memo(money)(coinLength) = result
        result
      }
    }

    println(solve(n, coin, coin.length))
  }

}

