l=gets.to_i n=gets.to_i w=gets.split(/\s/).map(&:to_i).sort{|a,b|b<=>a} s=[0] while w.size > 0 if s.inject(:+) + w.last <= l s.push(w.pop) else break end end puts s.size-1