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.with_index(1) do |y, n|
  # puts "??????#{n}??????"
  q = gets.to_i
  hoge = nil
  # p hoge
  amari = []

  q.times.with_index(1) do |y, i|
    counter = 1
    while q*counter-i <= cards.last do
      # puts "cards?????????#{cards}"
      # puts "-----?¨????#{counter}??????"
      # puts "??????#{q*counter - i}"
      # p cards.include?(q*counter - i)
      hoge = cards[cards.index(q*counter - i)] if cards.include?(q*counter - i)
      # puts "hoge:#{hoge} = q*counter - i"
      break unless hoge.nil?
      counter += 1
    end
    break unless hoge.nil?
  end

  # puts "??????#{hoge % q}"
  p hoge % q

end