#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	vector<int> AB,P;
	vector<int>::iterator it;
	int maxpoint = 0,n,m,in,key,c;

	cin >> n >> m;
	while(n != 0 && m != 0){

	for(int i = 0; i < n; i++){
		cin >> in;
		P.push_back(in);
	}

	P.push_back(0);
	sort( P.begin(),P.end() );

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			AB.push_back(P[i]+P[j]);
		}
	}

	AB.push_back(m+1);
	sort( AB.begin(),AB.end() );

	for(int i = 0; i < AB.size() ; i++){
		key = m - AB[i];
		if(key < 0)	break;
		else	c = upper_bound(AB.begin(),AB.end(),key) - AB.begin() - 1;
		maxpoint = max(maxpoint,AB[i] + AB[c]);
	}

	cout << maxpoint << endl;
	
	maxpoint = 0;	
	AB.clear();
	P.clear();

	cin >> n >> m;
	}
	return 0;
}