#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 = 15
    @m = 6
    @ds = [1,2,7,8,12,50]
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
#    

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


    v1 = rec(index + 1, left - @ds[index]) + 1 # include
    v2 = rec(index + 1, left) # not include

    v = [v1,v2].min
#if left == 8 && index == 3
#    puts "HHHH"
#end
#        print "                ",index,":",left,":",v,"\n"
    @dp[index][left] = v
    return v
end

puts rec(0,@n)

#
#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)