INF = 10**8
N, M = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
# p arr
dp = Array.new(M+1){Array.new(N+1, INF)}
dp.each do |d|
  d[0] = 0
end
1.upto(M) do |i|
  1.upto(N) do |j|
    if j - arr[i-1] < 0
      dp[i][j] = dp[i-1][j]
    else
      dp[i][j] = [dp[i-1][j], dp[i][j - arr[i-1]] + 1].min
    end
  end
end
# p dp
p dp[M][N]
