import std.stdio;
import std.string;
import std.conv;

import std.algorithm.mutation : copy;
import std.algorithm.iteration: uniq;

void main() {
    
    for(;;) {
        
        // input
        int n, m;
        {
            auto temp = readln.split;
            n = to!int(temp[0]);
            m = to!int(temp[1]);
        }
        
        if(n == 0 && m == 0) {
            break;
        }
        
        int[] p;
        p.length = n + 1;
        for(int i=0; i<n; ++i) {
            auto temp = readln.chomp;
            p[i] = to!int(temp);
        }
        p[$ - 1] = 0;

        // calc
        int[] twice;
        twice.length = p.length ^^ 2;
        {
            int i = 0;
            foreach(val1; p) {
                foreach(val2; p) {
                    twice[i++] = val1 + val2;
                }
            }
        }
        twice.length -= twice.sort.uniq.copy(twice).length;
        
        int ret;
        loop: foreach(val1; twice) {
            foreach(val2; twice) {
                
                int temp = val1 + val2;
                
                if(temp > m) {
                    break;
                } else if(temp == m) {
                    ret = m;
                    break loop;
                }
                
                if(temp > ret) {
                    ret = temp;
                }
            }
        }
        
        // output
        writeln(ret);
    }
}