n,m =gets.chomp.split(" ").map{|i| i.to_i}

coin=Array.new
coin=gets.chomp.split(" ").map{|i| i.to_i}
coin.sort!

count= 0

while m >=1
	while n>coin[m-1]
		n-=coin[m-1]
		count+=1
	end
	m-=1
end
puts count