### main

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

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

qn.times do
  max_rem = 0

  q = gets.strip.to_i

  for c in cards
    rem = c % q
    max_rem = rem if max_rem < rem
  end

  puts max_rem
end