
n,m = gets.split.map &:to_i
cm = gets.split.map &:to_i

def cm.get_the_number_of_coin(n)
  t = Array.new(n+1, Float::INFINITY)
  t[0] = 0

  self.each do |c|
    for j in c..n
      t[j] = [t[j], t[j-c]+1].min
    end
  end
  t[n]
end

puts cm.get_the_number_of_coin(n)

