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 current  = x
    for (i in sorted.indices) {
        if (sorted[i] <= current) {
            current -= sorted[i]
        } else {
            print(i)
        }
    }

    if (current == 0) {
        print(n)
    } else {
        print(n - 1)
    }
}