number_cards, number_questions = gets.split.map do |tmp|
  tmp.to_i
end
cards = gets.split.map do |tmp|
  tmp.to_i
end
cards.sord!
number_questions.times do

  q = gets.to_i
  hoge = 0
  counter = 0
  q.times.with_index(1) do |i|
    while q*counter < cards.last do
      counter += 1
      q*counter
      hoge = cards[cards.index?(q*counter-i)]
      break unless hoge.nil?
    end
  end

puts hoge % q

end