number_cards, number_questions = gets.split.map do |tmp|
  tmp.to_i
end
cards = gets.split.map do |tmp|
  tmp.to_i
end
cards.sort!
number_questions.times do
  amari = []
  q = gets.to_i
  amari << cards.last % q
  if amari[0] == q-1
    puts amari[0]
  else
    rep_cards = cards
    while true do
      hikaku = rep_cards.last - amari.last
      rep_cards = rep_cards.select{|rc| hikaku > rc}
      break if (rep_cards.last == nil)
      amari << rep_cards.last % q
      break if (amari.last == q-1)
    end
    puts amari.max
  end
end