
#include <stdio.h>
#include <algorithm>

using namespace std;

int n, m;
int p[1001];
int sp[1001*1001];

int main()
{
	for (;;)
	{
		scanf("%d %d", &n, &m);
		if (!n && !m)break;
		for (int i = 0; i < n; ++i)
		{
			scanf("%d", &p[i]);
		}
		p[n] = 0;
		int it = 0;
		for (int a = 0; a <= n; ++a)
		{
			for (int b = 0; b <= a; ++b)
			{
				sp[it++] = p[a] + p[b];
			}
		}
		sort(sp, sp + it);
		int *fr = sp;
		int *bk = sp + it - 1;
		int ans = 0;
		while(fr <= bk)
		{
			if ((*fr) + (*bk) <= m)
			{
				ans = max(ans, (*fr) + (*bk));
				++fr;
			}
			else
			{
				--bk;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}