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