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

  q = gets.to_i
  last_amari = cards.last % q


  amari = cards.map do |c|
    c % q
  end

  puts amari.max

end