#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<map>
#include<algorithm>
#include<stack>
#define P pair<int,int>
using namespace std;

int g[1000005];
int main() {
	int a, b, c[1001];
	while (scanf("%d%d", &a, &b), a | b) {
		for (int d = 0; d < a; d++)scanf("%d", &c[d+1]);
		c[0] = 0;
		int sum = 0;
		for (int e = 0; e <= a; e++) {
			for (int f = e; f <= a; f++) {
				g[sum] = c[e] + c[f];
				sum++;
			}
		}
		sort(g, g + sum);
		int MAX = 0;
		for (int l = 0; l < sum; l++) {
			auto x = upper_bound(g, g + sum, b - g[l]);
			x--;
			if(g[l]<=b)MAX = max(MAX, g[l] + *x);
		}
		cout << MAX << endl;
	}
}