
number_cards, number_questions = gets.split.map{ |i|
  i.to_i
}

cards = gets.split.map{ |i|
  i.to_i
}

questions = []
number_questions.times do
  questions << gets.to_i
end

questions.each do |q|
  remainder = cards.map do |c|
    c % q
  end

  puts remainder.max
end