l = gets.to_i n = gets.to_i inputs = gets.split(" ") n.times do |i| inputs[i] = inputs[i].to_i end inputs.sort! count = 0 n.times do |i| if l-inputs[i] >= 0 count += 1 l -= inputs[i] else break end end puts count