fun main(args: Array) { var L = readLine()!!.toInt() val N = readLine()!!.toInt() val W = readLine()!!.split(" ").map(String::toInt) val sorted_W = W.sorted() var cnt = 0 for (Wi in sorted_W) { if (Wi <= L) { L -= Wi cnt += 1 } else { break } } println(cnt) }