questions = []
number_cards, number_questions = gets.split.map do |tmp|
  tmp.to_i
end
cards = gets.split.map do |tmp|
  tmp.to_i
end
number_questions.times do
  questions << gets.to_i
end
questions.each do |q|
  rest_list = []
  cards.each do |c|
    rest = c % q
    rest_list.push(rest) unless rest_list.include?(rest)
  end
  p rest_list.reverse!
  p rest_list[0]
end