fun main(args: Array<String>) {
    val input = readLine()!!.split(" ").map { it.toInt() }
    val n = input[0]
    val x = input[1]
    val a = readLine()!!.split(" ").map { it.toInt() }
    val sorted = a.sorted()
    var total = 0
    var answer = 0
    if (sorted.any { it > x}) {
        print(0)
        return
    }

    for (i in sorted.indices) {
        total += sorted[i]
        if (x <= total) {
            answer = i + 1
            print(answer)
            return
        }
    }
    if (total < x) {
        answer = n - 1
    } else if (total == x) {
        answer = n
    }

    print(answer)
}