n, k = gets.split.map(&:to_i) a = [] n.times do a << gets.to_i end b = [] (1..n).each do |i| a.combination(i).each do |x| b << x.sum end end p (x = b.select{|i| i <= k}.max) ? x : 0