N,M = gets.split.map(&:to_i)
coins = gets.split.map(&:to_i)
inf = 10 ** 12

dp = Array.new(M+1) {Array.new(N+1){inf}}
dp[0][0] = 0

(0...M).each do |i|
  (0..N).each do |j|
    if j >= coins[i]
      dp[i+1][j] = [
        dp[i+1][j - coins[i]] + 1,
        dp[i][j],
      ].min
    else
      dp[i+1][j] = dp[i][j]
    end
  end
end

puts dp[M][N]

