#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}.reverse
end




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

@flag = false
def rec(index,left)


#    if (left == 8 && index == 3 ) || @flag
#        [index,left,@dp[3][8]].each do |e|
#           print e,"," 
#        end
#        puts ""
#        @flag = true
  
#    end
    
#    puts history if left == 0
    return 0 if left == 0
    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

v = rec(0,@n)
if v < 50000
   puts v 
else
   puts @n
end
#
#def test(i,j)
#    j += 1
#    return 0 if i == 5
#    print "PRE:",i,":",j,"\n"
#    test(i+1,j)
#    print "POST:",i,":",j,"\n"
#end
#
#puts test(0,1)