n,m = gets.split(" ").map(&:to_i)
dp = Array.new(m){Array.new(n+1,0)}
coins = gets.split(" ").map(&:to_i)
#coins ??????
coins.each_with_index do |coin,index|
  #???????????????????????????
  (n+1).times do |value|
    #?????¨??????coin??????????????????????????????????¶???????????????????
    case
    when index >= 1 && value-coin > 0
      #???????????£?????????????????¨???
      dp[index][value] = [dp[index-1][value], dp[index][value-coin]+1].min
    when value-coin == 0
      #coin????????????????????????0??????1?????\??????
      dp[index][value] = 1
    when index == 0 && value-coin > 0
      #?????????????????????????????¨???
      dp[index][value] = dp[index][value-coin]+1
    when index >= 1 && !(value-coin > 0)
      #???????????£?????????????????¨???
      dp[index][value] = dp[index-1][value]
    end
  end
end
puts dp[m-1][n]