import std.stdio, std.string, std.conv, std.typecons;

alias Tuple!(int, "num", int, "used") E;

void main(){
    int n, m;
    int p[300];
    E dp[];
    dp.length = 20000001;
    while(true){
        auto input = readln.split;
        n = input[0].to!int;
        m = input[1].to!int;
        if(m >= dp.length)
            throw new Exception(m.to!string);

        if(n == 0 && m == 0) break;
        foreach(i; 0..n){
            p[i] = readln.chomp.to!int;
        }
        foreach(i; 1..m + 1){
            bool changed;
            foreach(j; 0..n){
                if(i >= p[j]){
                    int sum = dp[i - p[j]].num + p[j];
                    if(dp[i].num < sum && dp[i - p[j]].used < 4){
                        dp[i].num = sum;
                        dp[i].used = dp[i - p[j]].used + 1;
                        changed = true;
                    }
                }
            }
            if(!changed){
                dp[i] = dp[i - 1];
            }
        }
        dp[m].num.writeln;
    }
}