L=gets.to_i N=gets.to_i W=gets.split.map(&:to_i).sort t=0 W.each do |i| L-=i if L<0 puts t exit end t+=1 end puts N