l = gets.to_i n = gets.to_i w = gets.split.map &:to_i w.sort! sum = 0 cnt = 0 w.each do |i| break if sum+i > l sum+=i cnt+=1 end puts cnt