fun main(args:Array) { val (n, k) = readLine()!!.split(" ").map{ it.toInt() } val a = (1..n).map { readLine()!!.toInt() }.sorted().reversed().toMutableList() var s = 0 for(b in a) { if( s < k ) { if( b+s <= k ) s = s + b } else break } println(s) }