width = gets.to_i
n = gets.to_i
array = gets.split.map(&:to_i).sort

# 入ったブロックの数
count = 0
# 小さいブロックから箱に入れて箱の幅更新
array.each do |w| 
  if width >= w then
		width -= w
		count += 1
	else
	  break
	end
end

puts count