l=gets.to_i #length of the box n=gets.to_i #number of blocks w=gets.split().map(&:to_i).sort! #array of width of blocks #puts l,n,w if w.inject(:+)l puts 0 return end #if w[0]==l #puts 1 #return #end sum=0 count=0 i=0 while sum + w[i] <= l sum += w[i] count+=1 i+=1 end puts count