MODE = "stdio" tmp = Array.new if(defined? MODE) tmp = STDIN.read.split("\n") else iotmp = "\ 100 10 14 85 77 26 50 45 66 79 10 3 ".split("\n") iotmp.each{|s| tmp << s.strip } end w = tmp[0].to_i n = tmp[1].to_i blocks = tmp[2].split(" ").map(&:to_i) blocks.sort! cnt = 0 blocks.each do |b| w -= b cnt += 1 if w>=0 end puts cnt