def solution(n, m, coins)
  dp = [0] + [Float::INFINITY] * n
  for coin in coins
    for amount in 0..n
      if amount >= coin
        dp[amount] = [dp[amount], dp[amount - coin] + 1].min
      else
        dp[amount] = dp[amount]
      end
    end
  end
  dp[n]
end


first_line = gets.split.map(&:to_i)
coins = gets.split.map(&:to_i)
p solution(first_line[0], first_line[1], coins)
