l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i).sort count = 0 w.each do |w| l -= w break if l < 0 count += 1 end puts count