const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');
const answers = [];

while (line = lines.shift()) {
	const [n, max] = line.split(' ').map(Number);
	if (n === 0 && max === 0) { break; }
	let prices = lines.shift().split(' ').map(Number);

	const sorted = prices.sort((a,b) => b - a).filter(a => a < max);
	let highestPossible = 0;
	let pair = 0;

	sorted.forEach(price => {
		if (!highestPossible && price < max) {
			highestPossible = price;
		}
		if ((highestPossible && highestPossible + price) <= max) {
			pair = price;
		}
	});
	
	answers.push(highestPossible + pair);
} 

