### main

n, qn = gets.strip.split(' ').map{|s| s.to_i}

cards = gets.strip.split(' ').map{|s| s.to_i}.sort
max_c = cards.last

qn.times do
  q = gets.strip.to_i

  max_rem = max_c % q
  qi = q - 1
  prev = 0

  for c in cards
    if c <= qi
      prev = c
      next
    end

    rem = prev % q
    max_rem = rem if max_rem < rem

    prev = c
    qi += q
    while qi < c
      qi += q
    end
  end

  puts max_rem
end