import core.stdc.stdio;
import std.range;
import std.algorithm;

void main(){
	int[] buf_p = new int[1001];
	int[] buf_d = new int[1001*500];
	while(1){
	
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==0&&m==0)
		break;
	int[] p = buf_p[0..++n];
	foreach(ref v;p[1..$])
		scanf("%d",&v);
	p[0]=0;
	int[] d=buf_d[0..n*(n-1)/2];
	int c=0;
	foreach(i;0..n)
		foreach(j;i+1..n)
			d[c++] = p[i]+p[j];
	sort(d);
	int ans;
	foreach(v;d){
		if(v*2>m)
			break;
		auto lb = d.assumeSorted.lowerBound(m+1-v);
		if(!lb.empty)
			ans=max(ans,v+lb[$-1]);
	}
	printf("%d\n",ans);
	
	}
}