
fun main(args:Array<String>):Unit {
    var (n, m) = readLine()!!.split(' ').map(String::toInt)
    while(n != 0 || m != 0){
        val points = Array(n + 1){if (it == 0) 0 else readLine()!!.toInt()}
        val pair = points.indices.flatMap {a ->  (a until points.size).map{b -> points[a] + points[b]} }.filter{it <= m}.sorted().toIntArray()
        println(pair.map{point ->
            val idx = pair.binarySearch(m - point).let{if (it < 0) -it - 2 else it}
            if (idx in pair.indices){
                point + pair[idx]
            }else point
        }.max())
        val (nn, mm) = readLine()!!.split(' ').map(String::toInt)
        n = nn
        m = mm
    }
}
