import std.array;
import std.range;
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

int bsearch(int[] a, int b) {
    size_t lo=0,hi=a.length-1;
    while(hi>=lo) {
    	size_t mi = (hi+lo)/2;

	if(a[mi] > b) hi = mi - 1;
	else lo = mi + 1;
    }

    return a[hi];
}

int[] uniq(int[] a)
{
	int[] res;
	foreach(v; a)
	  if(res.empty||res[$-1] != v) res ~= v;

	return res;
}
 
void main()
{
    while(true) {   
        int N,M;
	scanf("%d%d", &N, &M);
        if(N==0&&M==0) break;
         
	int[] inp = new int[](N+1);
        inp[0] = 0;
 
        foreach(i; 0..N) {
	    scanf("%d", &inp[i+1]);
        }
 
        N++;
 
        int[] add2 = new int[](N*N);
 
        foreach(i; 0..N) foreach(j; 0..N)
            add2[j*N + i] =  inp[i] + inp[j];
     
        add2.sort;
	int[] a = uniq(add2);

        int res;
        foreach(v; a)
        {
            if(v > M) break; 
            res = max(res, v + bsearch(a, M-v));
        }
 
        writeln(res);
      }
}