
import std.stdio;
import std.range;
import std.algorithm;
import std.string;
import std.conv;
import std.array;
import std.math;

string getLine() {
  return readln.strip.chomp;
}

// start から num 個の組み合わせ
int[] comb(int[] seq, int start, int num) {
  int[] res;
  for (int i; i < pow(num, num); i++) {
    int sum = 0;
    for(int j = i; j > 0; j = j / num) {
      sum += seq[start + j % num];
    }
    res ~= sum;
  }
  return res;
}

void main() {
  while (true) {
    int[] line = getLine.split(" ").map!(to!(int)).array;
    int times = line[0];
    int threshold = line[1];
    if (times == 0 && threshold == 0) break;    
    auto seq = iota(times).map!((_) => getLine.to!(int)).array.sort;
    int n = seq.map!(x => x * 4).assumeSorted.lowerBound(threshold).length.to!(int) - 3;
    if (n < 0) n = 0;
    int min = min(seq.length, 4);
  
    reduce!((max, x) {
        if (x <= threshold && x > max) {
          max = x;
        }
        return max;      
      })(0, comb(seq, n, min)).writeln;
  }
}