fun main(args: Array) { var bigBox = readLine()!!.toInt() var numOfSmallBox = readLine()!!.toInt() var smallBoxes = readLine()!!.split(" ").map { it.toInt() } val sorted = smallBoxes.sorted() var boxList = mutableListOf() var total = 0 for (i in 0 until numOfSmallBox) { total += sorted[i] if (total > bigBox) { break } else { boxList.add(sorted[i]) } } println(boxList.size) }