/**
 * @link http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_A&lang=jp
 */
fun main(args: Array<String>) {
    Main.init()

    Main.execute()

    Main.display()
}

class Main {
    companion object {

        private val MAX_PRICE = 50000

        private val matrix = arrayListOf<IntArray>()

        private var requiredPrice: Int = 0
        private var coinNum: Int = 0


        private lateinit var coinList: List<Int>

        fun init() {
            val (inputRequiredPrice, inputCoinNum) = readLine()!!.split(" ")
            requiredPrice = inputRequiredPrice.toInt()
            coinNum = inputCoinNum.toInt()

            // matrixを準備
            for (index in 1..this.coinNum) {
                matrix.add(IntArray(requiredPrice + 1) {
                    if (it == 0) 0 else MAX_PRICE
                })
            }

            coinList = readLine()!!.split(" ").map(String::toInt)
        }


        fun execute() {
            /**
             * matrixを走査
             */
            var round = 0
            while (coinList.lastIndex >= round) {
                val coinPrice = coinList[round]

                val currentRound = matrix[round]
                val previewRound = if (round == 0) IntArray(requiredPrice + 1) { if (it == 0) 0 else MAX_PRICE } else matrix[round - 1]

                for (price in 0 until currentRound.size) {

                    val coinNumWhenNone = previewRound[price]

                    if (price - coinPrice < 0) {
                        currentRound[price] = coinNumWhenNone
                        continue
                    }

                    val coinNumWhenAdded = currentRound[price - coinPrice] + 1

                    if (coinNumWhenAdded < coinNumWhenNone) {
                        currentRound[price] = coinNumWhenAdded
                    } else {
                        currentRound[price] = coinNumWhenNone
                    }
                }
                round++
            }
        }

        fun display() {
            println(matrix.last().last())
        }
    }
}
