n, q = gets.chomp.split.map(&:to_i)
h = {}
gets.chomp.split.map(&:to_i).each{|x| h[x] = true}
max = h.keys.max

q.times{
    d = gets.to_i
    (d - 1).downto(0){|i|
        m, found = 0, false
        while d * m + i <= max
            if h[d * m + i]
                puts i
                found = true
                break
            end
            m += 1
        end
        break if found
    }
}
