L = gets.to_i N = gets.to_i w = gets.split.map(&:to_i) a = 0 ans = 0 w.sort! while L > a and w.size > 0 a += w.shift ans += 1 if L < a ans -= 1 end end puts ans