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
    x = (c + rest)/q
    x.upto(x) do
      kaburi = c*x+rest
      cards.pop(kaburi) if cards.include?(kaburi)
    end
    rest_list.push(rest) if rest > rest_list.max
  end
  p rest_list.max
end