L=gets.to_i N=gets.to_i Ws= gets.split.map(&:to_i).sort count=0 ans=0 N.times do |n| count+=Ws[n] break if count>L ans=ans+1 end puts ans