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