# 0270: Modular Query
# ??????????????????????????°?????????????????°?????§?????£???????????????????????§???????±???????????????°??????
# 2 <= number_cards     <= 300000 ?????????????????°
# 2 <= number_questions <= 100000 ???????????°
# 1 <= cards            <= 300000 ??????????????°???
# 1 <= questions        <= 300000 ???????????°???

# ??\????????????????????° ???????????° -> ex)3 3
number_cards, number_questions = gets.split.map do |tmp|
  tmp.to_i
end

# cards = []
questions = []

# ??\??????????????????????????????????????°??? -> ex)9 3 8
cards = gets.split.map do |tmp|
  tmp.to_i
end

# ??\?????????????????°??? ->
# 4??????
# 6??????
# 5??????
number_questions.times do
  questions << gets.to_i
end

cards.sort!

questions.each do |q|

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

  replica_card = cards.select{ |x| hikaku > x }
        #replica_card????????????(?????§???-?????§????????????)??\????????°???

  # p replica_card
  replica_card << last_num
        #replica_card?????????????????§????????¨???(?????§???-?????§????????????)??\????????°???

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

end