loop do
  n, m = gets.chomp.split.map(&:to_i)

  break if n == 0 && m == 0

  nums = {}
  board = [0]

  n.times do
    num = gets.to_i
    board << num
    nums[num] = true
  end

  max_value = 0
  second_scores = board.repeated_combination(2).map(&:sum).uniq.sort

  second_scores.each do |n|
    a = 0
    b = second_scores.size - 1

    rem = m - n
    next if rem < 0

    while a < b
      c = (a + b) / 2

      if rem > second_scores[c]
        a = c + 1
      elsif rem < second_scores[c]
        b = c
      else
        break
      end
    end

    v = second_scores[b - 1]
    max_value = [max_value, n + v].max
  end

  puts max_value
end


