_, K = gets.split.map(&:to_i) max = 0 A = readlines.map(&:to_i) A.length.downto(1) do |n| max = [ (A.combination(n).to_a.map { |ary| ary.inject(0, &:+) }.reject { |a| a > K }.max || 0), max ].max break unless max.zero? end puts max