fun main(args: Array<String>) {
    println(calculator.calculate(calculator.input()))
}

val calculator = Calculator({
    val x = readLine()!!.split(" ")[1].toInt()
    val list = readLine()!!.split(" ")
            .asSequence()
            .map { it.toInt() }
            .sorted()
    Pair(x, list)
}, { input ->
    var x = input.first
    var ret = 0
    var flag = false
    ret += input.second.filter {
        when {
            x >= it -> {
                x -= it
                true
            }
            x + input.second.first() == it -> {
                x -= it
                flag = true
                true
            }
            else -> false
        }
    }.toList().size
    if (flag || x > 0)
        ret--
    ret.toString()
})

data class Calculator<T>(val input: () -> T, val calculate: (T) -> String)
