if !ENV['RUBY_THREAD_VM_STACK_SIZE']
    #Rubyパスを取得するには、rbconfigかrubygemsを使う。AtCoderでは--disable-gemsされているので、require 'rubygems'は必須である。
    #require 'rbconfig';RUBY=File.join(RbConfig::CONFIG['bindir'],RbConfig::CONFIG['ruby_install_name'])
    require 'rubygems';RUBY=Gem.ruby
    exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},RUBY,$0) #100MB
end

count = 0
$n = 0
$m = 0
coin_str = ""
STDIN.each_line {|line|
  if count == 0
    count = 1
    n_m = line.split " "
    $n = n_m[0].to_i
    $m = n_m[1].to_i
  end

  coin_str = line
}

$coin_list = coin_str.split " "
$coin_list.map! {|item| item.to_i }
# $coin_list.sort! {|a, b| b <=> a }

$coin_count_map = {}
for index in 1..$n
  $coin_count_map[index] = $n + 1
end

$coin_count_map[0] = 0
def solve i
    if i == $m
      return $coin_count_map[$n]
    end

    # if n == 0
    #   return $coin_count_map[0]
    # end

    now_coin = $coin_list[i]
    for price in now_coin..$n
      $coin_count_map[price] = [$coin_count_map[price], $coin_count_map[price - now_coin] + 1].min
    end
    # tmp = n - coin
    # solve i + 1

  return solve i + 1
end

puts solve 0
