l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i).sort ans = 0 n.times do |i| break if l < w[i] l -= w[i] ans += 1 end puts ans