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 = [0]
  cards.each do |c|
    rest = c % q
    if rest == q-1
      p rest
      break
    end
    rest_list.push(rest) if rest > rest_list.last
  end
  p rest_list.last if rest_list.length > 1
end