number_cards, number_questions = gets.split.map do |tmp|
  tmp.to_i
end

questions = []

cards = gets.split.map do |tmp|
  tmp.to_i
end

cards.sort!
number_questions.times do

  q = gets.to_i
  last_num = cards.last
  maxnum_amari = last_num % q
  hikaku = last_num - maxnum_amari

  replica_card = cards.select{ |x| hikaku > x }
  # p replica_card

  replica_card << last_num

  fuga = replica_card.map do |rc|
    rc % q
  end
  puts fuga.max

end