def bs(l, r, k)
  while r - l > 1
    mid = (l + r) / 2
    return mid if X[mid] == k
    if X[mid] <= k
      l = mid + 1
    else
      r = mid - 1
    end
  end
  return r
end

while true
  n, m = gets.split.map(&:to_i)
  break if n.zero?
  po = Array.new(n * 2, 0)
  p_ = n.times.map { gets.to_i }
  po[(1..n)] = p_
  X = []

  q = 0
  for i in (0..n)
    for j in (i..n)
      X[q] = po[i] + po[j]
      q += 1
    end
  end
  X.sort!

  res = 0
  for i in (0...q)
    if X[i] <= m
      t = X[i] + X[bs(0, q - 1, m - X[i])]
      res = t if (t <= m && t > res)
    end
  end
  p res
end