#Coin Changing Problem

debug = false

unless debug
    @n,@m = STDIN.gets.split(" ").collect{|e| e.to_i}
    @ds = STDIN.gets.split(" ").collect{|e| e.to_i}
else
    @n = 50000
    @m = 20
    @ds = "1 92 1377 3168 7095 1170 1809 5046 3225 1054 4016 142 108 6430 3970 48 8416 4909 114 6968".split(" ").collect{|e| e.to_i}
end

@min = (@ds - [1]).min


@dp = Array.new(@m){Array.new(@n)}

def rec(index,left)

    return 0 if left == 0
    return left if left < @min
    return 50000 if index == @m || left < 0
    unless @dp[index][left] == nil
        return @dp[index][left]         
    end

    v0 = rec(index,left - @ds[index]) + 1 # incdlue more than one
#    v1 = rec(index + 1, left - @ds[index],history + index.to_s) + 1 # include just one
    v2 = rec(index + 1, left) # not include

    v = [v0,v2].min

   @dp[index][left] = v
    return v
end


puts rec(1,@n)