l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i).sort sum = 0 count = 0 w.each do |w| sum += w count += 1 if l <= sum puts count - 1 return end end if sum < l puts 1 end