n, m = gets.chomp.split.map(&:to_i)
coins = gets.chomp.split.map(&:to_i).sort
coins.delete(1)
arr = (0..n).to_a
coins.each{|coin|
    1.upto(n){|x|
        q, r = x.divmod(coin)
        x2 = x
        0.upto(q){|q2|
            arr[x] = [q2 + arr[x2], arr[x]].min
            x2 -= coin
            break if q2 >= arr[x]
        }
    }
}
puts arr[n]
