import std.stdio;
import std.string;
import std.conv;

import std.algorithm.mutation: copy;
import std.algorithm.iteration: uniq;

int binarySearch(int[] arr, int require) {
    size_t left = 0, right = arr.length - 1;

    while(left <= right) {
        size_t index = (left + right) / 2;
        
        if(arr[index] > require) {
            right = index - 1;
        } else {
            left = index + 1;            
        }
    }
    
    return arr[right];
}

void main() {
    
    for(;;) {
        
        // input
        int n, m;
        {
            auto temp = readln.split;
            n = to!int(temp[0]);
            m = to!int(temp[1]);
        }
        
        if(n == 0 && m == 0) {
            break;
        }
        
        int[] p;
        p.length = n + 1;
        for(int i=0; i<n; ++i) {
            auto temp = readln.chomp;
            p[i] = to!int(temp);
        }
        p[$ - 1] = 0;

        // calc
        int[] twice;
        twice.length = p.length ^^ 2;
        {
            int i = 0;
            foreach(val1; p) {
                foreach(val2; p) {
                    twice[i++] = val1 + val2;
                }
            }
        }
        twice.length -= twice.sort.uniq.copy(twice).length;
        
        int ret = 0;
        foreach(val; twice) {
            
            if(val > m) {
                break;
            }
            
            int temp = val + binarySearch(twice, m - val);
            if(temp > ret) {
                ret = temp;
            }
           
        }
        
        // output
        writeln(ret);
    }
}