## subroutines

def lower_bound(arr, key, i0 = 0, i1 = arr.length)
  lb = i0 - 1
  ub = i1

  while lb + 1 < ub
    m = (lb + ub) / 2
    if arr[m] <= key
      lb = m
    else
      ub = m
    end
  end
  lb
end

### main

loop do
  n, m = gets.strip.split(' ').map{|s| s.to_i}
  break if (n | m) == 0

  ps = []
  n.times do
    ps << gets.strip.to_i
  end

  p2s = [0] + ps
  for i in (0...n)
    for j in (i...n)
      p2s << ps[i] + ps[j]
    end
  end

  p2ss = p2s.uniq.sort
  np2s = p2ss.length
  #p p2ss

  max_sc = 0

  for p2 in p2ss
    break if m < p2
    rem = p2ss[lower_bound(p2ss, m - p2)]
    #p [m - p2, rem]
    sc = p2 + rem
    max_sc = sc if max_sc < sc
  end

  puts max_sc
end