n = gets.chomp.to_i m = gets.chomp.to_i b = gets.chomp.split.map(&:to_i).sort c = 0 m.times do |i| if n - b[i] >= 0 n -= b[i] c += 1 end end p c